How can I get json objects without the object number?

I have a simple json object that spits out 4 items that have completely different properties inside each one. I have got the json being displayed with the 4 objects that are called meta.work_content like so:

[Object, Object, Object, Object]

I can open these in console and see the objects like so:

0: Object
1: Object
2: Object
3: Object

I can go further into each one etc. In my javascript I have got a simple ajax request getting the items with the following setup:

var getPosts = function() {

        $.ajax({
          url: '/wp-json/posts?type=case-studies',
          data: {
            filter: {
            'name': _last
            }
          },
          success: function ( dataS ) {
            //List some global variables here to fetch post data
            // We use base as our global object to find resources we need
            var base = dataS[0];
            console.log(base);
            var postContent = base.content;
            var postTitle = base.title;
            // Main Image ACF object
            var featuredImage = base.meta.main_image;
            // Gallery ACF object
            var nodes = base.meta.work_content;
            // output ACF objects
            console.log(nodes);
          },
          cache: false
        });

    };

Now here comes the tricky part, I want to access each meta.work_content object but without using this to do it base.meta.work_content[0], base.meta.work_content[1] etc as each items order will change and so these numbers will be irrelevant.

The items need to be access based on their object name not the [0],[1],[2] as thats not going to work.

Cheers


Source: json

Leave a Reply