Self referencing an Array of JSON to call a function / to update

I’m currently transitioning from VueJS to AlpineJS and trying to update specific JSON arrays but it doesn’t seem to be updating.

An example:

Any tips or reasonings why this is not working?

var foo = [

          { id: 0, title: 'test', text: c( this ) },
          { id: 1, title: 'test', text: 'text' },
          { id: 2, title: 'test', text: 'text' },

      ]
function c( idk ) {
    console.log( idk.title )
  }


console.log(foo)
var foo = (() => {

  // Paste in your original object
  const foo = [ {
    a: 5,
    b: 6,
  }
  ];
  
  // Use their properties
  foo.c = foo.a + foo.b;

  // Do whatever else you want

  // Finally, return object
  return foo;
})();

  console.log( foo )

These examples were from Self-references in object literals / initializers but has been modified to use an Array of JSON

57 thoughts on “Self referencing an Array of JSON to call a function / to update”

Leave a Comment