sudan kanakavel sudan kanakavel - 2 months ago 6
JSON Question

How to delete an entire column in an array using JavaScript

I have array of 3 columns (array has 6000 evalues and so each colum of array have 6000 values) in json file and store in variable called data. Using java script i need to store only first two columns of an array in a variable called edata. That is edata should contain array of two column of 6000 values.

That is 2 colum contain 6000 values each. Third colum should not be present.

Kindly help me in finding solution to it. I tried slice function but it only give 2 values as output i need 2 entire colums. that is from [[a,b,c],[a,b,c],[a,b,c],[a,b,c],[a,b,c]]............ to [[a,b],[a,b],[a,b],[a,b]]...........

$.ajax({
url: "xxxxxxxxxxxxxxxxxxx",
type: 'GET',
context: document.body,
success: function(data){
//console.log(data);
// http call for end
var edata = data.slice(1,2);
var series= [{
name: 'Touches',
color: 'rgba(223, 83, 83, .5)',



data: edata

Answer

You can use the map function for this.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

var edata = data.map(function(obj) {
    return {field1: obj.field1, field2: obj.field2}
}
Comments