2

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"]
2
  • 5
    use R.pluck('name', [{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}]) Commented Nov 22, 2019 at 9:53
  • please add it as an answer, so that i can accept, This works. Thanks Commented Nov 22, 2019 at 9:55

2 Answers 2

6

You can use pluck function:

R.pluck('name', [{name: "Abc"}, {name: "Xyz"}, {name: "lmn"}])
Sign up to request clarification or add additional context in comments.

1 Comment

@StepUp: Ramda is a functional programming library; we don't talk about methods but about functions! (R is not logically an OOP object, but simply a namespace.)
0

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);

2 Comments

Hi Saurabh, the OP was asking about how Ramda could help, specifically. This solution you suggest doesn't use Ramda at all.
Sorry, but I still don't see any Ramda in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.