Working on an Angular 2 application and attempting to identify the difference between two arrays (last seven days and missing dates within the last seven days). Everything works fine when initializing the array through a string, like in example code 1. However, there seems to be an issue when retrieving data from the database.
var array1 = ['20180605', '20180606', '20180607', '20180608', '20180609', '20180610', '20180611']
var array2 = ['20180606', '20180607', '20180608']
var ind
for (var i = 0; i < array2.length; i++) {
ind = array1.indexOf(array2[i])
if (ind > -1) {
array1.splice(ind, 1)
}
}
console.log('diff', array1)
However, the method above is not performing as expected.
let datas = [
{'dateString': '20180607'},
{'dateString': '20180606'},
{'dateString': '20180608'}
]
let originalDataArray = []
for (let data of datas) {
originalDataArray.push(data.dateString)
}
let dataArray = []
function formatDate (subtractDate) {
let datestring
datestring = moment().subtract(6 - subtractDate, 'days').format('YYYY' + 'MM' + 'DD')
dataArray.push(datestring)
}
let lastSevenDaysArray = []
for (let i = 0; i < 7; i++) {
let date = formatDate(i)
}
var array1 = originalDataArray
var array2 = dataArray
var ind
for (var i = 0; i < array2.length; i++) {
ind = array1.indexOf(array2[i])
if (ind > -1) {
array1.splice(ind, 1)
}
}
console.log('diff', array1)