0

I have following 2 arrays of object. I want to convert the array from 1st format to 2nd format, i.e, data values stored from int to string, but unable to find a convinient way. Can someone help? enter image description here

Please, help out with a way to do so easily by Javascript.

2 Answers 2

3

Try this:

The map() method creates a new array with the results of calling a provided function on every element in this array.

var test = [{
  id: 0,
  title: 0
}, {
  id: 1,
  title: 1
}, {
  id: 2,
  title: 2
}, {
  id: 3,
  title: 3
}];
var newArray = test.map(function(item) {
  return {
    id: item.id.toString(),
    title: item.title.toString()
  };
});
console.log(newArray);

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

Comments

3

Use map, for example:

tootSetArray.map(function(item){
  return {
    id: '' + item.id,
    title: '' + item.title
  };
});

The map() method creates a new array with the results of calling a provided function on every element in this array.

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.