javascript - Combine 2 arrays and fill with 0 if they are not duplicates -


i have 2 arrays datetimes. want display values in x-axis of chart.

i need function combine arrays in 1 , add '0' aren't duplicates.

array 1 = [2016-01-20,2016-01-21,2016-01-24] array 2 = [2016-01-21]  final array = [0, 2016-01-21, 0] 

is there quick way this?

thank much

you can map() , indexof()

var array1 = ['2016-01-20', '2016-01-21', '2016-01-24']  var array2 = ['2016-01-21']    var final = array1.map(function(e) {    return (array2.indexof(e) == -1) ? e = 0 : e;  });    console.log(final)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -