Skip to content

Tag: ecmascript-6

Swapping array with alternative numbers

In an array take alternate numbers and swap them. Put it again in the place of array again e.g., arr = [8,7,4,6,9,3,2,1] newarr= [8,1,4,3,9,6,2,7] The Code which I tried is below one This is not the correct way to proceed. Answer When you consider every odd indexed element to be alternate –

Filter an array nested within an object

I was able to find many sources saying how to filter nested arrays, but all of these referred to arrays within arrays. In my case, there’s an array nested within an object and I can’t figure out how to deal with it. The source array is: How to filter the nested array so that the resulting object l…