I need to check equals values in my array. I try many ways but no one works.
I try:
var sorted_arr = this.variacaoForm.value.variacoes.sort(); the comparing function here.
for (var i = 0; i < this.variacaoForm.value.variacoes.length - 1; i++) {
if (sorted_arr[i + 1].sku == sorted_arr[i].sku) {
console.log('Equals elements array')
}
}
In this way, the first and the third element never fire a console.log()
Also try:
for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
if(this.produto.sku_prin == this.variacaoForm.value.variacoes[i].sku){
console.log('Equal values array');
}
}
in this way i receive console.log same if i don't have equal value
Also:
for (let i = 0; i < this.variacaoForm.value.variacoes.length-1; i++) {
for (let j = i+1; j < this.variacaoForm.value.variacoes.length; j++) {
if (this.variacaoForm.value.variacoes[i].sku === this.variacaoForm.value.variacoes[j].sku) {
console.log('x')
}
}
}