I want to combine two arrays into one Object with name "data" Didn't find any efficient way
arrays:
var N =[ 1, 2, 3];
var s =[ a, b, c];
combine them into object:
var data= { s:[ a, b, c], N: [ 1, 2, 3 ] };
Just pass your arrays (N and s) as variables to your new object. You can do this in few ways:
let myObject = { N: N, s: s } If you do this way you can type any other key. For example: let myObject = { firstArray: N, secondArray: s } and now you can access to N and s arrays as myObject.firstArray etc
Use short notation: let myObject = { N, s } This code will look up for variables N and s and write it inside your new object, which will give the same result as let myObject = { N: N, s: s }
var data = {s: s, N: N};! Or in recent ECMAScripts:var data = {s, N};!var data = { s, N };(ES6)