Features of ECMAScript 2015 (Math + Number + String + Object API)?

How can I get the value of each iterator of an array object?
I'm just a little confused, can anyone help?

let x, y, z; x = ["a", "b", "c"].entries(); console.log("x = " + x); // iterator [0, "a"], [1,"b"], [2,"c"] y = ["a", "b", "c"].keys(); console.log("y = " + y); // iterator 0, 1, 2 z = ["a", "b", "c"].values(); console.log("z = " + z); // iterator "a", "b", "c" // x = [object Array Iterator] // y = [object Array Iterator] // z = [object Array Iterator] /* how to can I get the value of each array object iterator? */ 

http://babeljs.io/repl/? enter image description here

0
source share
2 answers

You can use Array.from() to convert an iterator object to an array:

 const arr = ['a', 'b', 'c'] console.log(Array.from(arr.keys())) 

See also Iteration Protocols on MDN.

+3
source

Here is my solution!

You can follow my steps if you have an obstacle!

https://github.com/gildata/RAIO/issues/61

Steps

  • objects into an array, {{},{}} => arr = [{},{}];

for entry and keys

  1. get the name of the object, title = key;

for entry and keys

  1. create a new object obj = {title, arr};

Object.assign (obj, {new_key: "new value"});

  1. wrapped array, array.push(obj);

for the function f in

  1. just use a wrapped array

array.map () and table

  // fetch data by `ReportName` & `GetRowSchema` outputClick = () => { fetch(`https://cdn.xgqfrms.xyz/json/tables.json`) .then((response) => response.json()) .then((json)=> { console.log(`json = ${json}`); console.log(`json.length = ${json.length}`); console.log(`json.Info`, json.Info.schema.Properties); // Properties let datas = []; if(json.Info.schema.Properties !== undefined){ // datas.BasicInformationRow.Properties datas = json.Info.schema.Properties; }else{ let tables = json.Info.schema; // let i = 0; for (let key in tables) { let arr = []; let new_obj = {}; let i = 0; if(!tables.hasOwnProperty(key)) continue; if (tables.hasOwnProperty(key)) { let title = tables[key].desc, objs = tables[key].Properties; for (let key in objs) { if (objs.hasOwnProperty(key)) { // A0 objs[key].name = key; objs[key].key = ("k000" + i++); } arr.push(objs[key]); console.log(`arr ${key}`, arr); } console.log(`title ${key}`, title); new_obj.title = tables[key].desc; new_obj.datas = arr; console.log(`new obj = `, new_obj); } datas.push(new_obj); const css = ` color: #0f0; font-size: 23px; `; const css2 = ` color: #f00; font-size: 16px; `; console.log(`%c datas key = ${key} \n datas = `, css, datas); console.log(`%c datas i = ${i} \n datas = `, css2, datas[i]); // i++; } } console.log(`datas[0] = `, datas[0]); console.log(`datas[0].length = `, datas[0].length); // Array.isArrray(datas[0]); console.log(`Array.isArray(datas[0]) = `, Array.isArray(datas[0])); console.log(`typeof datas[0] = `, typeof(datas[0])); this.setState( { output_datas: datas } ); return datas; }); }; 
0
source

Source: https://habr.com/ru/post/886185/


All Articles