I have been tasked with importing Excel files containing customer orders into my web application. The process involves converting the data in the file into an object of arrays, where each array represents a row from the Excel sheet.
Once the data is imported, I need to search for specific items within a column to identify the shoe brands requested by customers. However, I encountered an issue where the same column data was being pushed into the array multiple times instead of just once.
In the code snippet below, you can see how I attempted to address this problem using conditional statements:
for (let i = 0; i < this.data.length; i++) {
if (this.data[i].indexOf('Adidas') !== -1) {
let brandIndex = this.data[i].indexOf('Adidas');
for (let j = 0; j < this.data.length; j++) {
this.brandArray.push(this.data[j][brandIndex]);
}
} else if (this.data[i].indexOf('Puma') !== -1) {
let brandIndex = this.data[i].indexOf('Puma');
for (let j = 0; j < this.data.length; j++) {
this.brandArray.push(this.data[j][brandIndex]);
}
} else if (this.data[i].indexOf('Nike') !== -1) {
let brandIndex = this.data[i].indexOf('Nike');
for (let j = 0; j < this.data.length; j++) {
this.brandArray.push(this.data[j][brandIndex]);
}
}
}
The current implementation pushes the column data into the array every time a condition is met. Is there a more efficient way, possibly utilizing the '%' operator or another function, to ensure that each column is only added to the array once?
If, for example, I had a customer sheet with the following entries:
https://i.stack.imgur.com/G62py.png
I would like the resulting array to be
[Nike, Adidas, Puma, Puma, Asics, Nike]