So I have the following array:
var hdr = ("name", "date", "start_time", "selling_item", "total_call",
"end_time", "ad_num", "area", "order_num");
//this data is returned from db
Now I want to replace it with proper naming convention, so I do this:
renameTableHdr(hdrs){
var handler = hdrs;
for(var a = 0; a<hdrs.length; a++){
// console.log(hdrs[a]);
var itm = "";
if(hdrs[a] === 'name'){
itm = "Name";
}
if(hdrs[a] === 'ad_num'){
itm = "Ad Number";
}
if(hdrs[a] === 'date'){
itm = "Date";
}
if(hdrs[a] === 'order_num'){
itm = "Order Number";
}
if(hdrs[a] === 'start_time'){
itm = "Start Time";
}
if(hdrs[a] === 'area'){
itm = "Area";
}
if(hdrs[a] === 'selling_item'){
itm = "Selling Item";
}
if(hdrs[a] === 'end_time'){
itm = "End Time";
}
if(hdrs[a] === 'total_call'){
itm = "Total Call";
}
if(handler.indexOf(hdrs[a]) >= 0){
handler.splice(handler.indexOf(hdrs[a]),1);
}
this.tempTblHdr.push(itm);
}
},
So if I'm not doing splice, data returned is correct or the expected one. But with splice, it's not doing it well.
Result without splice
(9) ["Ad Number", "Date", "Order Number", "Start Time", "Name", "Area", "Selling Item", "End Time", "Total Call", __ob__: Observer]
With Splice
(5) ["Ad Number", "Order Number", "Name", "Selling Item", "Total Call", __ob__: Observer]
//other 4 data are missing
I'm removing this items from handler for they are the main needed data that is needed to be in proper naming convention, and there's possibility that it is added. I'm renaming them without touching or changing their indexes. Am I doing the splice correctly?
hrds[a] = itm?const translated = {name:'Name'};const hdrs = handler.map(item=>translated[item]);