convert to an array code example
Example 1: javascript object to array
const numbers = {
one: 1,
two: 2,
};
console.log(Object.values(numbers));
console.log(Object.entries(numbers));
Example 2: javascript convert to array
console.log(Array.from('foo'));
console.log(Array.from([1, 2, 3], x => x + x));
Example 3: number to array js
const arrayOfDigits = numToSeparate.toString().split("");
Example 4: javascript to array
Array.from("Hello");
Example 5: array from js
console.log(Array.from(length, (_,i) => i));
console.log(Array.from({LENGTH}, (_,i) => i));
console.log(Array.from({length}, (_,i) => i));
console.log(Array.from(Array(length), (_,i) => i));
Example 6: convert array to array
new_images = array();
for ($i = 0; $i < count($images['name']); $i++) {
$new_images[] = array(
'name' => $images['name'][$i],
'type' => $images['type'][$i],
'tmp_name' => $images['tmp_name'][$i],
'error' => $images['error'][$i],
'size' => $images['size'][$i],
);
}
<pre>Array
(
[name] => Array (
[0] => Screen Shot 2020-10-21 at 10.44.30 AM.png
[1] => Screen Shot 2020-10-21 at 9.56.12 AM.png )
[type] => Array (
[0] => image/png
[1] => image/png )
[tmp_name] => Array (
[0] => /Applications/MAMP/tmp/php/phpnlVcZU
[1] => /Applications/MAMP/tmp/php/php1qaHkj )
[error] => Array (
[0] => 0
[1] => 0 )
[size] => Array (
[0] => 61923
[1] => 62194)
)
</pre>
<pre>Array
(
[0] => Array (
[name] => Screen Shot 2020-10-21 at 10.44.30 AM.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpJz6xqI
[error] => 0
[size] => 61923 )
[1] => Array (
[name] => Screen Shot 2020-10-21 at 9.56.12 AM.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpHSBXaI
[error] => 0
[size] => 62194 )
)
</pre>