Here is an object:
var a = { a: 1, b: 2, c: 3};
I would need to square all values from this object and the keys to remain the same, so new object to look like this:
var a1 = {a: 1, b: 4, c: 9}
My code - I extracted the keys and the values and created two separate arrays:
var a = {a:1, b: 2, c:3};
let key = Object.keys(a);
let value = Object.values(a);
v = [];
for (var i=0; i<value.length;i++){
value[i]**2;
v.push(value[i]**2);
}
console.log(v);
So here I got the array with squared values of all elements, but I don't know how to return it back to the object and get
{a: 1, b: 4, c: 9}