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
vote
1 answer

PHP adding array values to multidimensional arrays

Possible Duplicate: Array push with associate array I am trying to design a php program to crawl a website and recursively follow all links until the entire website is searched. To accomplish this, I am trying to use a multidimensional array,…
user905080
  • 15
  • 2
1
vote
4 answers

Evenly push values from a flat array into same positioned rows of a 2d array

I need to evenly/synchronously push values from my second array into the rows of my first array. The arrays which have the same size, but with different keys and depths. The first is an array of rows and the second is a flat array. $array1 = [ …
Myers
  • 148
  • 8
1
vote
2 answers

array_push in PHP seems to get into infinite loop

I am new to PHP. I am trying to read MySQL with this PHP code. .... $sql = "select * from GameMaster where UserId = '".$_POST["UserId"]."'"; $result = mysqli_query($link, $sql); $rows = array(); $return = array(); while($row =…
David Kim
  • 41
  • 5
1
vote
1 answer

Laravel array_push returns undefined offset error

Code $loans2ndChart = Loan::select('date_release') ->where('invalid',false) ->where('transaction_year', $transyear) ->get() ->groupBy(function($date)…
Eli
  • 1,256
  • 4
  • 29
  • 59
1
vote
2 answers

For aggregating elements at an array instance within a constructor can `[].push.apply(this, arr)` be replaced with something that performs faster?

This line in my constructor function takes 0.15ms to execute. [].push.apply(this, selector); Please don't tell me 0.15ms time is acceptable. I am hoping there is some faster option. Because I think this line is converting NodeList/HTMLCollection to…
samar
  • 135
  • 1
  • 8
1
vote
1 answer

Count two array items with same name as one

I have multidimensionnel array with different types of items but there are repeated items by name with quantity, I want to count each product total quantity in one array. I have tried some solutions like if(in_array) but no luck !. I also have tried…
crackry
  • 55
  • 6
1
vote
0 answers

Php Array Splice does not compare size

The array should push new item in array instead of increasing quantity when size is different, but it increases quantity and overwrites size of the previous item. Has anybody a constructive solution please? if (isset($_POST['pid'])) { $pid =…
Said
  • 19
  • 5
1
vote
2 answers

Add another item to array associative in php

im having some issues adding a new item to an associative array, This is how i'm creating my structure: $cpdata[$count] = array( 'value' => $value->value, 'images' => array( 'color' => $value->color, 'image' => $value->image, …
mxr10
  • 11
  • 3
1
vote
1 answer

AngularJs copy : does not placed in the second row in table

I have a problem that I'm having a hard time with, I don't know how I can add into second row when I click the button using angularJS it always on the first row, sorry for my english. Here's my template
1
vote
1 answer

Getting error message for array_push method in php

Here is the code for my class: dataArray = array(); echo"Created new Location instance
"; } …
banditKing
  • 9,405
  • 28
  • 100
  • 157
1
vote
2 answers

How to push nested object interface array in React Typescript using useState

Interface interface ListInterface { listName: string; list: string[]; } useState const [initialList, setinitialList] = useState({listName: "List1", list:['One', 'Two', 'Three', 'Four', 'Five', 'Six']}); const…
1
vote
1 answer

how to use array_push() in JAVASCRIPT?

I'm new to JavaScript , I have a problem to get new array like one array result day = ['sday','mday','tday']; val = [1,2,3] when I use array push var array = []; $.each(resp.result, function(index, item) { array.push(item.day); …
lara data
  • 25
  • 5
1
vote
1 answer

How to create a multidimensional array with values from dynamically created form fields, using jquery?

I have a form where I dynamicly add three fields at time. Those fields each have diffrent class names. I want to create a multidimensional array that stores the values of those fields. The array needs to look like this: var working_days = { …
1
vote
0 answers

Remove duplicate values from queryin PDO php query

I'm trying to run a search query for a blog site I'm working on, I used the explode function to separate my search string and as a result when I loop the results I get duplicate results. The code is as follows }}else{ $searchbit= explode(" ",…
Kudzie99
  • 33
  • 1
  • 7
1
vote
1 answer

PHP Adding to Existing Array Created in foreach

I am selecting values from a database and adding these to an array in a foreach loop, this works. After this I am selecting additional values in a second query, I want to add these values to the same array, how can I achieve this? Please note I am…
jonboy
  • 2,729
  • 6
  • 37
  • 77