0

I have an array of objects as shown below

Array1
(4) [{_index: "sitelist", _source:{dma: 1 , site :4}},{_index: "sitelist", _source:{dma: 2 , site :4}},{_index: "sitelist", _source:{dma: 3 , site :4}},{_index: "sitelist", _source:{dma: 4, site :4}}]

Now i wanted to retrieve the source object and store it in an array , desired output should be

Array2 
(4) [{dma: 1 , site :4},{dma: 2 , site :4},{dma: 3 , site :4},{dma: 4 , site :4}]

I have tried using the filter function as

let Array2 = Array1.filter(function(obj){
                return obj._source;
            });

When i console.log(Array2) i am not getting the desired result, i am getting Array1 values, How to get the proper output, any help appreciated.?

2 Answers 2

1

Try this: Map

let result = Array1.map(x=>x._source)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use delete:

let Array2 = Array1.filter(function(obj){
                 return delete(obj._index);
             })

1 Comment

If you what to use filter

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.