I'm currently faced with a scenario where I need to loop through an array of objects. Specifically, when there are more than two objects in the array and the first object is missing, how can I skip it and move on to the next one?
Check out the loop below:
for (i = 0; i < this.myInputFields.myTextFields.length; i++) {
if (!this.myInputFields.myTextFields[i] || this.myInputFields.myTextFields[i] == null || this.myInputFields.myTextFields[i] === '') {
// Move to the next object
}
if (this.myInputFields.myTextFields[i].key) {
data[this.myInputFields.myTextFields[i].key] = this.myInputFields.myTextFields[i].inputValues;
}
}
Here's the printed array example when the first object is missing:
[ ,
{ type: 'textfield',
placeholderText: 'Enter your number',
title: '*number',
key: 'signedByNumber',
inputType: 'numbers',
inputValues: '553' } ]
If you noticed, before the second object there is a comma followed by a space that I need to skip somehow.