Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push elements dynamically using javascript

Tags:

javascript

I am getting the points from the multidimensional array using map, but I am getting array of array values.

I need the below format:

[36, 122, 25]

But I'm getting the multi array of points.

Below is my code and output

var data = [{
    "name": "ramu",
    "id": "719",
    "gmail": "[email protected]",
    "ph": 988989898,
    "points": 36
  },
  {
    "name": "ravi",
    "id": "445",
    "gmail": "[email protected]",
    "ph": 4554545454,
    "points": 122
  },
  {
    "name": "karthik",
    "id": "866",
    "gmail": "[email protected]",
    "ph": 2332233232,
    "points": 25
  }
]

var result = data.map(function(arr, count) {
  return [arr.points];
});

console.log(result);

output is:

[[36], [122], [25]]
like image 485
ramu Avatar asked Apr 12 '26 15:04

ramu


1 Answers

Try below code:

var data = [{"name":"ramu","id":"719","gmail":"[email protected]","ph":988989898,"points":36},
        {"name":"ravi","id":"445","gmail":"[email protected]","ph":4554545454,"points":122},
        {"name":"karthik","id":"866","gmail":"[email protected]","ph":2332233232,"points":25}]          
var result = data.map(function(arr, count) {  return arr.points;});
console.log(result);
like image 149
Akash Shrivastava Avatar answered Apr 15 '26 03:04

Akash Shrivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!