NicolaFilosa_SE
2 years agoContributor
Delete particular element of an array
Hi to everyone, I have a problem handling an array. I have an array that contains a null element (""), and I want to remove this element from the array.
I tried it but it does not work:
for (var i=0; i<Devices_List.length; i++)
{
if ( Devices_List[i].contentText == "")
// Deletes the item
{
Devices_List.DeleteItem[i]
}
}
Thanks in advance to everyone that helps me
See Array.prototype.splice() for example,
function MyArray() { var myArray = ["One", "Two", "Three", "", "Five"]; for (var i = 0; i < myArray.length; i++) { if (myArray[i] === "") { myArray.splice(i, 1); break; } } for (var i = 0; i < myArray.length; i++) { Log.Message(myArray[i]); } }