简体   繁体   中英

Ramda, pulling a json index from array

I have the following array, containing similar JSON objects,

[{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}]

How can Ramda help me in achieving the following

["Abc", "Xyz", "lmn"]

You can use pluck function:

R.pluck('name', [{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}])

You can also do it using Array.prototype.map()

Try this:

 let array = [{ name: "Abc" }, { name: "Xyz" }, { name: "lmn" }] let res = array.map((value) => { return value.name; }) console.log(res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM