There is such an array array

how do i convert it to such an array with objects

[{ 0:{login: "Проверочный опрос"}, 1:{login: "Первый опрос"}, 2:{login: "Все типы ответов"} }] 
  • 2
    {login: ["Проверочный опрос", "Первый опрос", "Все типы ответов"]} . Do it like this - ArchDemon
  • @ArchDemon how? - Dune Konaren
  • Hospadi var a = ["Проверочный опрос", "Первый опрос", "Все типы ответов"]; var b = {login: a}; - ArchDemon
  • @ArchDemon is okay, how can I convert to such an array with objects?) [{0: {login: "Verification Poll"}, 1: {login: "First Poll"}, 2: {login: "All Types of Responses"} }] - Dune Konaren
  • @ArchDemon I do for (var i = 0; i <this.data.length; i ++) this.dataarray = [{login: this.data [i]}] and it only saves the last option in the list passed in a loop like me save all? - Dune Konaren

1 answer 1

 const array = ['Проверочный опрос', 'Первый опрос', 'Все типы ответов']; const transformed = array.reduce((accumulator, value) => { accumulator.push({ login: value }); return accumulator; }, []); 
  • thanks, really helped) - Dune Konaren