array-splice

Best way to delete “column” from multidimensional array

狂风中的少年 提交于 2019-11-27 02:15:23
问题 I have a multidimensional php array that represents a table like this ------------- | A | 0 | A | |---|---|---| | 0 | 0 | 0 | |---|---|---| | A | 0 | A | ------------- so the array looks like this: array (size=3) 0 => array (size=3) 0 => string 'A' (length=1) 1 => string '0' (length=1) 2 => string 'A' (length=1) 1 => array (size=3) 0 => string '0' (length=1) 1 => string '0' (length=1) 2 => string '0' (length=1) 2 => array (size=3) 0 => string 'A' (length=1) 1 => string '0' (length=1) 2 =>

Deleting array elements in JavaScript - delete vs splice

旧城冷巷雨未停 提交于 2019-11-25 21:41:55
问题 What is the difference between using the delete operator on the array element as opposed to using the Array.splice method? For example: myArray = [\'a\', \'b\', \'c\', \'d\']; delete myArray[1]; // or myArray.splice (1, 1); Why even have the splice method if I can delete array elements like I can with objects? 回答1: delete will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined: > myArray = ['a', 'b', 'c', 'd'] ["a", "b"