0

I am having an array of arrays in Javascript, like

[
    ["2019","abc","xyz"],
    ["2014","DEF","PQR"]
]

How can I convert the above array into array of objects like,

[
    {
        date: 2019,
        name:abc,
        address:xyz
    },
    {
        date: 2014,
        name: DEF,
        address: PQR
    }
]
0

3 Answers 3

2

You can use Array.map to build desired format, here i am Destructuring element from each array as date, name, and address and than returning an object with these key/value pair

let data =  [["2019","abc","xyz"],["2014","DEF","PQR"]]

let op = data.map(([date, name, address]) => ({date, name, address}))

console.log(op)

Sign up to request clarification or add additional context in comments.

Comments

2

You can use Array.map

let arr = [["2019","abc","xyz"],["2014","DEF","PQR"]];
let result = arr.map(([data,name,address]) => ({data, name, address}));
console.log(result);

Comments

0

a simple routine

var arr = [["2019","abc","xyz"],["2014","DEF","PQR"]];

var output = [];

arr.forEach(function(el){

    output.push({
        date: el[0],
        name: el[1],
        address: el[2]
    });
});

console.log(output)

1 Comment

You can create a running code snippet read here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.