Questions tagged [array-push]

array-push refers to the javascript Array.prototype.push() method. The push() method adds one or more elements to the end of an array and returns the new length of the array.

refers to the javascript Array.prototype.push() method.

The push() method adds one or more elements to the end of an array and returns the new length of that array. developer

Example

var a = []; //or new Array()
var i = a.push('foo', 'bar');
console.log(i, a); 

the console will display the values

2 ["foo", "bar"]

The counterpart to push() is pop(), which removes the last item from an array.

Documentation

382 questions
-1
votes
2 answers

Why are the strings not being added into the PHP array?

I am trying to create an array holding the dates of each title. However the $dates array is var_dumping int(1) rather than an array. And $dates[0] is NULL. The csv files follow this formatting: log_2013_14_04.csv. The substr is working fine and…
Willow
  • 1,040
  • 2
  • 10
  • 21
-2
votes
2 answers

html rendering inside array_push

I am trying to pass html (image tag) inside an array_push: array_push($result, array("id"=>$value, "label"=>''.$value, "value"=>strip_tags($key))); The problem is that the html is rendered in the page like…
Yannis
  • 912
  • 2
  • 14
  • 34
-2
votes
1 answer

How to append the array elements to existing JSON in javascript

I have an array which consists of the string elements something like this: a = ['First Name', 'Last Name', 'Age'] the actually array is quite large so I have given a small example here. I have another Json object which has few elements…
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
-2
votes
3 answers

array_push with associative array

I have an array like this: $allauto = [ 'name' => $title, 'type' => 'simple', 'description' => $description, 'attributes' => [ [ 'id' => 1, 'visible' => true, …
Redman
  • 133
  • 1
  • 1
  • 10
-2
votes
3 answers

Array_push pushing empty values

I'm trying to push data to an array inside a foreach loop. Empty values get pushed into the array. I tried logging out the values to see if they were empty but they were there, they only go missing when pushing to the array. I also tried to just…
ReynaMoon
  • 171
  • 1
  • 12
-2
votes
3 answers

How to push a found array item into another array?

I have an array. But trying to separate items. For example: $array1 = ["banana","car","carrot"]; trying to push car into another array which is $array2 $push = array_push($array1, "car") = $array2; I try to find array_push usage for this but the…
user10753862
-2
votes
1 answer

PHP transform old Array push syntax into new one

got some code like foreach ($aArray as $oObject) { array_push($this->_aOtherArray, array( 'foo' => $oObject->foo->value, 'bar' => $oObject->bar->value ) ); } Where I fill…
broxyl
  • 37
  • 6
-2
votes
1 answer

Add new value in multiple array PHP

I was searching around but still I can't find an answer. I have following array array:2 [ 0 => array:2 [ 0 => "Name" 1 => "Age" ] 1 => array:2 [ 0 => "Name" 1 => "Age" ] ] and I want to add new value 0 in all arrays. This is…
i-faith
  • 449
  • 1
  • 3
  • 14
-2
votes
1 answer

PHP: How to push an array into a 2D array?

In Perl, we could do like this: foreach (....) { .......... .......... .......... my @tmp = ($x1,$x2,$y1,$y2); push(@target_array,\@tmp); # Don't know how to translate this line to PHP, failed after several try with array_push } How…
Nissa
  • 215
  • 1
  • 7
-2
votes
1 answer

Why doesn't array.push() work when looping object?

I'm doing a simple Sudoku solver with JavaScript, and there is one problem with adding new values to array. My script makes random length arrays in for..in loop. I have tested this script with Chrome Debugger, and there I see that it loops right…
jartza
  • 13
  • 3
-2
votes
4 answers

Push items into array using eventlistener

I'm trying to update the array with values once the user clicks on an element in the DOM. The elements seem to be pushed into the array inside the anonymous function but outside the function the array is still empty. How can I fix that? Here is the…
Ryan Mc
  • 833
  • 1
  • 8
  • 25
-2
votes
2 answers

Iteration Push Alternative Javascript

Obviously, this is not allowed in javascript: for (var i=0; i
Alexey Ayzin
  • 209
  • 2
  • 21
-2
votes
2 answers

Pushing to array

I need to loop through array and each array in array that has extra values, push them to their parent array as separate item. I hope this makes sense.. This is the structure of my initial array: {type: [ 0: value: "tomato" ], […
Solo
  • 6,687
  • 7
  • 35
  • 67
-2
votes
1 answer

For loop through php array only shows last value

I'm having an array which I have included only once in the header.php file. header.php: array.php: In the order.php I'm having an array and code which is executed when…
Elvira
  • 1,410
  • 5
  • 23
  • 50
-2
votes
2 answers

Error using array_push

I am trying to use array_push but I am recieving error messages like: Warning: array_push() expects parameter 1 to be array, string given in C:\Users\DMR\Google Drive\android\maquetas\show.php on line 50 in two linews where I am using array_push, I…
Dave
  • 7,028
  • 11
  • 35
  • 58
1 2 3
25
26