Numpy array dimensions
Use .shape to obtain a tuple of array dimensions: >>> a.shape (2, 2)
Use .shape to obtain a tuple of array dimensions: >>> a.shape (2, 2)
The callback is passed the element, the index, and the array itself. arr.forEach(function(part, index, theArray) { theArray[index] = “hello world”; }); edit — as noted in a comment, the .forEach() function can take a second argument, which will be used as the value of this in each call to the callback: arr.forEach(function(part, index) { this[index] … Read more
Basically, Python lists are very flexible and can hold completely heterogeneous, arbitrary data, and they can be appended to very efficiently, in amortized constant time. If you need to shrink and grow your list time-efficiently and without hassle, they are the way to go. But they use a lot more space than C arrays, in … Read more
For simple array members like that, you can use JSON.parse. var array = JSON.parse(“[” + string + “]”); This gives you an Array of numbers. [0, 1] If you use .split(), you’ll end up with an Array of strings. [“0”, “1”] Just be aware that JSON.parse will limit you to the supported data types. If … Read more
Nope, there is no array_push() equivalent for associative arrays because there is no way determine the next key. You’ll have to use $arrayname[indexname] = $value;
If you are looking for a functional approach: var obj = {1: 11, 2: 22}; var arr = Object.keys(obj).map(function (key) { return obj[key]; }); Results in: [11, 22] The same with an ES6 arrow function: Object.keys(obj).map(key => obj[key]) With ES7 you will be able to use Object.values instead (more information): var arr = Object.values(obj); Or … Read more
No, that solution is absolutely correct and very minimal. Note however, that this is a very unusual situation: Because String is handled specially in Java, even “foo” is actually a String. So the need for splitting a String into individual chars and join them back is not required in normal code. Compare this to C/C++ … Read more
With array_intersect_key and array_flip: var_dump(array_intersect_key($my_array, array_flip($allowed))); array(1) { [“foo”]=> int(1) }
A working JSFIDDLE You can do something like this: var y = [1, 2, 2, 3, 2] var removeItem = 2; y = jQuery.grep(y, function(value) { return value != removeItem; }); Result: [1, 3] http://snipplr.com/view/14381/remove-item-from-array-with-jquery/
Since PHP 5.6, you can declare an array constant with const: <?php const DEFAULT_ROLES = array(‘guy’, ‘development team’); The short syntax works too, as you’d expect: <?php const DEFAULT_ROLES = [‘guy’, ‘development team’]; If you have PHP 7, you can finally use define(), just as you had first tried: <?php define(‘DEFAULT_ROLES’, array(‘guy’, ‘development team’));