My view object:
{
description: "2tik 2tags"
id: 100
portfolio: "TSLA"
term_id_1: 260751
term_id_2: 285493
term_id_3: null
ticker_1: "GOOG"
ticker_2: "TSLA"
ticker_3: ""
timespan: "ld"
top: ""
}
I need to grab the term_id
s and stick them into a new array, but only if they are not null
.
What I'm currently using:
function reSelectTags(view) {
console.log('view',view);
// Seperate term_ids:
var term_ids = [];
if (view.term_id_1 != null) {
term_ids.push(view.term_id_1);
}
if (view.term_id_2 != null) {
term_ids.push(view.term_id_2);
}
if (view.term_id_3 != null) {
term_ids.push(view.term_id_3);
}
console.log('term_ids',term_ids);
}
This gets the job done, but I'm wondering if there is a better, cleaner way, perhaps on 1 or 2 lines that could accomplish this as well.