Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

Convert the array of objects to object iterable

//example array 
const myArray = [
    { id: 1, name: "A" },
    { id: 2, name: "B" },
    { id: 3, name: "C" },
    { id: 4, name: "D" },
    { id: 5, name: "E" }
];
//converting array of objects to iterable objects
const obj = Object.assign({}, myArray);
//output
console.log(obj);
//output
/*
{0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}}
0: {id: 1, name: 'A'}
1: {id: 2, name: 'B'}
2: {id: 3, name: 'C'}
3: {id: 4, name: 'D'}
4: {id: 5, name: 'E'}
[[Prototype]]: Object
*/
 
PREVIOUS NEXT
Tagged: #Convert #array #objects #object #iterable
ADD COMMENT
Topic
Name
7+4 =