JSON to object array format
I want to display like convert JSON data to array objects how can solve this problem using jquery or js?
JSON data :
To array object:
one more pattern I need it I have an array like this in Ruby
to convert into add as key entry static
Firstly note that you do not need jQuery at all for this. jQuery is primarily a tool for amending the DOM. To work with data structures like this native JS is all you need.
To achieve what you require, you can use Object.keys() to get the keys of the 0th object in your original array, then you can loop over them using map() to build a new 2 dimensional array from that data:
Its simple enough. Just enter the array into Object.entries(). like this Object.entries(originalArr[0])
A simple one-line alternative:
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.