-2

I have an array of objects that looks like this: 🧨

[
  { apreciated_id: "123g1b1b23kbb3" },
  { apreciated_id: "asd567sad5a7sd" },
  { apreciated_id: "4hk3kjh234kjh4" }  
]

But I want it to look like this: 👨‍🎨

["123g1b1b23kbb3", "asd567sad5a7sd", "4hk3kjh234kjh4"]

How can I do it?

1
  • Array.prototype.map Commented Aug 22, 2020 at 0:29

2 Answers 2

0

Something like this should do it:

const arr = [
  { apreciated_id: "123g1b1b23kbb3" },
  { apreciated_id: "asd567sad5a7sd" },
  { apreciated_id: "4hk3kjh234kjh4" }  
]

const result = arr.map(obj => obj.apreciated_id)

Map takes an array of length n of some type (in this case objects) and trasnforms it according to a function, to an array of length n of some other type (in this case strings)

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

1 Comment

Thank you so much! It works! and now I get it 🔥
0

You can use the map() function to "transform" the array.

let arr = [
    { apreciated_id: "123g1b1b23kbb3" },
    { apreciated_id: "asd567sad5a7sd" },
    { apreciated_id: "4hk3kjh234kjh4" }  
];

let res = arr.map(a => a.apreciated_id);

console.log(res);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.