I need to convert object to several arrays, without duplicate keys, if there is a key that consist "user_" or "city_", create new array. The first three props/keys always are the same.
for example
const test = {
"mainPoint": "user1",
"create_Date": "2018-04-23 16:51:10",
"delete_Date": "2018-04-23 16:50",
"user_one": 4,
"user_two": 4,
"city_one": bs,
"city_two": mi
}
to this:
['user1','2018-04-23 16:51:10','2018-04-23 16:50','user_one',4]
['user1','2018-04-23 16:51:10','2018-04-23 16:50','user_two',4]
['user1','2018-04-23 16:51:10','2018-04-23 16:50','city_one','bs']
['user1','2018-04-23 16:51:10','2018-04-23 16:50','city_two','mi']
This is my code
let tempArr = [];
for(let key in test){
tempArr = [];
if(key.indexOf("user_") !== -1 || key.indexOf("city_") !== -1){
tempArr.push(test['mainPoint']);
tempArr.push(test['create_Date']);
tempArr.push(test['delete_Date']);
tempArr.push(key);
tempArr.push(test[key]);
}
console.log(tempParams);
}
thanks for any help!