-1

I have a newbie question regarding arrays and objects. I have an array of objects that I would like to push into another array of objects, but can't seem to get it to work correctly.

For instance, if I have data.list:

data.list=[{
  a,
  b, 
  c
}];

and I want to push data.list into another object array called data.overall so that it looks like this:

data.overall=[{
  data.list,
  z,
  y,
  x
}];

Sorry, for clarification, I want data.list to still exist as an array within data.overall. I've tried concat, but I keep getting an error in the console saying Server JavaScript error Cannot find function concat in object [object Object].

Thanks!

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Dave
  • 1,257
  • 2
  • 27
  • 58
  • So, what have you tried, what dd you expect to happen, and what happened instead? Have you read the documentation of Array? It lists all the methods, with a description and examples for all: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array – JB Nizet Sep 14 '18 at 14:22
  • 2
    It not valid Array itself, You have an array of Object, But Object should have properties – Mahesh G Sep 14 '18 at 14:28

1 Answers1

-2

As you said, newbie I am trying to help you,

Javascript Objects should have always properties like below and you wanted to achieve this? Let me know if you have any questions.

From your question, I assume that you wanted to achieve this, Hope this helps to proceed next with Javascript

And also you can always check how JSON should be structured with below URL

https://jsoneditoronline.org/

var data = [{
  "a": 1,
  "b": 2,
  "c": 3
}];

var dataNew = [{
  "x": 4,
  "y": 5,
  "z": 6
}]

function getData(data) {
  return data;
}

var modiFiedObject = [{
  "data": getData(data[0]),
  "dataNew": getData(dataNew[0])
}]

console.log(modiFiedObject);
Mahesh G
  • 1,226
  • 4
  • 30
  • 57