The output received is array of objects, sample format below:
However, my component expects JS Object in the following format:
Is following approach correct, please suggest better approach if any
asked Mar 10, 2017 at 9:25
6,66116 gold badges55 silver badges101 bronze badges
You could take a more functional approach with the following:
This uses the map method that is attributed with arrays to loop over each item of the array and return a new array of parsed objects.
Take a look at this fuller example.
answered Mar 10, 2017 at 9:57
Alex JonesAlex Jones
3303 silver badges14 bronze badges
I have another way to convert this content. Using
The result as following:
answered Mar 10, 2017 at 11:49
answered Mar 10, 2017 at 15:38
1,3802 gold badges14 silver badges19 bronze badges
This will give you jsonObj as your desired json object.
Hope this helps :)
answered Mar 10, 2017 at 9:40
Here's the fixed code: One error was when you've listed the content items, a "]" was missing at the end. The second one was that you were trying to assign a values to an undefined object, you first
need to define the object eg:
In order to have the output as an array, you just have to define the colection as an array and not am object eg:
answered Mar 10, 2017 at 9:35
How do you create a new copy of an object?
Use the Object. assign() method. Use the JSON. stringify() and JSON..
First, create a new object named person ..
Second, clone the person object using the Object. assign() method..
Third, change the first name and address information of the copiedPerson object..
How do I create an object in es6?