I need to extract closest lower value and closest higher value in a javascript objet. My logic is to iterate on the objet and put in a variable all values which are inferior than the value of my product (then do the same with the closest higher value and all values which are superior)
The value that I want to extract in that example is the date that is the first value of the object which is constructed like this : "object":[[val1, val2],[val1, val2]]
Do you think my logic is the good one, and can you see what's wrong with my code?
var datagrph = $.parseJSON('{"label":"Yo", "fromDate":"2015-06-05", "launchDate":"2016-08-15", "dateValues":[["2014-06-05",1723.76], ["2015-06-29",1523.76], ["2015-12-29",1023.76], ["2017-01-29",523.76], ["2017-02-22",1523.76], ["2017-03-29",523.76], ["2017-04-29",1523.76], ["2017-05-29",23.76], ["2017-06-21",523.76] ]}');
var productCour = datagrph.dateValues;
var launchDate = datagrph.launchDate;
var val1 = [0];
Object.keys(productCour).map(function(objectDate, index) {
var value = object[objectDate];
if (value <= launchDate) {
val1.push(value);
} else if (value > launchDate) {
value++;
}
return val1;
});
alert(val1);