How to push additional fields to a javascript array from an oData result

How to push additional fields to a javascript array from an oData result

I have a ramdom array in javascript

I have a ramdom array in javascript

var dataModel = [];

I've queried an oData url and I want to fill the result in my dataModel [] array. And, for each item I want to add additional fields

odataMod.read(
        "/",
        null, [],
        true,
        function (oData, oResponse) {
            var data = oData.results;

        data.forEach(function (item) {
            //Add the object 
            dataModel.push(item);
            //I want to add additional fields to every object in data 
            dataModel.push(item.ObjectType = "Chevron");
            dataModel.push(item.HierarchyNodeLevel = 0);
            dataModel.push(item.IsCriticalPath = false);
            dataModel.push(item.IsProjectMilestone = false);
            dataModel.push(item.DrillDownState = "expanded");
            dataModel.push(item.Magnitude = 5);

...

Note : the ObjectType , DrillDownState , Magnitude (etc...) are the fields that I want to add with their values Chevron, 0, false (etc...)

Below is a screenshot of the current result :

But I want to add the additional properties inside each item and not outside , what I am doing wrong? In other word, I want the additional fields to be inside the metadata

Below is a sc of where I would like to add the items :


javascript arrays

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Learn Arrays And Array Methods in JavaScript

In JavaScript, an array is a data structure that contains list of elements which store multiple values in a single variable. The strength of JavaScript arrays lies in the array methods. Array methods are functions built-in to JavaScript that we can apply to our arrays — Each method has a unique function that performs a change or calculation to our array and saves us from writing common functions from scratch. In this video we are going to learn arrays and array methods like sort(), reverse(), join(), split(), pop(), push(), shift(), unshift(), toString(), delete array, etc.......

Javascript Clear Array: How to Empty Array in Javascript

To clear array in Javascript, Substituting an existing array with a new array.Setting an array length prop to 0.Splice the whole array.

Convert String To Array Using Javascript Split Method

In this tutorial, you’ll be going to learn how to convert string to array using javascript split method. The easiest approach to use javascript built-in method String.split(). JavaScript split string method return array of a substring after splitting a string based on the separator you provide. The separator might be a string, special character or […]

JavaScript 2D Array: Create Two Dimensional Array in JavaScript

To create a 2D array in JavaScript, we have to create an array of array. To declare a 2D array, use the same syntax as declaring a 1D array.

How To Loop Through An Array In JavaScript

In this tutorial, you'll be going to learn how to loop through an array in javascript. The easiest way to use for loop and forEach array method.