1

I have a multidimentional array in javascript like this

Arr[i].ProductId
Arr[i].ProductName
Arr[i].ProductCode
Arr[i].ProductDescription
Arr[i].ProductOrigin
Arr[i].ProductInfo

Arr is populated with data when everything is done with Arr,I want to have another array without (ProductCode,ProductOrigin,ProductInfo) columns.

I have done this

var list2 = JSON.parse(JSON.stringify(Arr));
for (i in list2) {
    delete list2[i].ProductCode;
    delete list2[i].ProductOrigin;
    delete list2[i].ProductInfo;
}

this is iterating through the array. is it possible to remove the Columns without iterating? or what is the better solution for that?

2
  • No, there is no method to delete parts of an object array in constant time. Commented Jan 29, 2022 at 8:31
  • Where is the multi dimensional part of your array? Looks like you just have an object array Commented Jan 29, 2022 at 8:37

1 Answer 1

2

You need to iterate over the list to get the new version of every element. Another way to do this is using Array#map:

const list2 = Arr.map(({ ProductCode, ProductOrigin, ProductInfo, ...e }) => e);
Sign up to request clarification or add additional context in comments.

1 Comment

The Map function doesn't work on Edge

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.