J
J
jizzy2020-04-24 20:51:51
JavaScript
jizzy, 2020-04-24 20:51:51

Javascript how do I multiply an array element by 2?

let newArr =
{
    "example": "name",
    "word": 12,
    "word": "noone",
    "word": "2014",
    "result": [
        {
            "name": "Ivan",
            "age": "20"
        },
        {
            "name": "OIga",
            "age": "30"
        }
    ]
};
let newArr2 = [ ];

how do i multiply the age by 2 and push it into a new array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tigran Abrahamyan, 2020-04-24
@jizzy

let newArr = 
    {
      "example": "name",
      "word": 12,
      "word": "noone",
      "word": "2014",
      "result": [
        {
          "name": "Ivan",
          "age": "20"
        },
        {
          "name": "OIga",
          "age": "30"
        }
      ]
    };

let newArr2 = newArr.result.map(el => el.age * 2);

let newArr3 = newArr.result.map(el => {
  return {name: el.name, age: el.age * 2};
});

console.log(newArr2);
console.log(newArr3);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question