0

I have an object like

const obj = {
   apple:'red',
   banana:'yellow'
}

I need to return an array with properties/values using ramda.

Example:

[
    {
        name: 'apple',
        value:'red'
    },
    {
        name: 'banana',
        value:'yellow'
    },
]
0

2 Answers 2

3

A ramda solution:

R.pipe(
  R.toPairs,
  R.map(R.zipObj(['name', 'value']))
)(obj)
Sign up to request clarification or add additional context in comments.

Comments

1

You can achieve that without any 3rd party lib, with Object.entries, that returns an array with an array that contains key & value, map over it to convert it to an object.

const obj = {
  apple: 'red',
  banana: 'yellow'
};

const result = Object.entries(obj)
  .map(([name, value]) => ({
    name,
    value
  }));

console.log(result);

Comments

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.