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: Combining data of multiple jsons to array

I have the following data (i have a lot more). $item1 = '{"views":{"Greece":{"total":10},"Cyprus":{"total":23},"Bulgaria":{"total":1},"United States":{"total":53},"United…
Vicky Dallas
  • 15
  • 1
  • 5
1
vote
3 answers

Adding items to a multidimensional array without overwriting the old ones?

this may be a simple question, yet I haven't been able to find an answer to it: How do I add a value to an array without overwriting (all) old values, or having to rewrite them? Is there such a thing as array_push in LUA? And if so, does it work for…
Chris
  • 2,905
  • 5
  • 29
  • 30
1
vote
3 answers

Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes)

I'm trying to create a Java file using a PHP script, but for some reason, whenever I run this script I get the following error on the screen: Fatal error: Allowed memory of 134217728 bytes exhausted (tried to allocate 24 bytes) in…
Ido
  • 171
  • 2
  • 13
1
vote
2 answers

php session array add an element if same ID

I got below session array to store cart items: print_r($_SESSION['items']): Array ( [0] => Array ( [p_name] => Product A [p_price] => 13.90 [p_seller] => 2001 ) [1] => Array ( …
Nanny Boy
  • 107
  • 6
1
vote
3 answers

push function changes props in react

this is my problem. when I use the push() function it changes my props in react. const prioship = (this.props.orders.prioshipping === false ? {'name':`Regular Shipping`,'price':'0','currency':'EUR','quantity':1, 'description': ''} :…
Mar
  • 1,129
  • 1
  • 13
  • 18
1
vote
3 answers

How to store each array value with their keys in php

I want to store my variables in an array alongside their keys like : filter : [ "0" : "test", "1" : "you", "2" : "php" ] I have filter[] array in the first place and each time with update request I want to add a value to this array with it's key,…
Mohammad_Hosseini
  • 2,481
  • 3
  • 30
  • 53
1
vote
2 answers

php array_push and array_intersect

I want to add value to array and then I want to use these arrays in array intersect. Codes are in bellow. Where am I doing mistake? $array =['1,2,3,4','3,4,5','2,3']; $arr2 = []; $common = []; for($i=0; $i
Halim
  • 65
  • 9
1
vote
1 answer

JS add array in tracking code push method

I've been trying since yesterday to pass an array in a push method. There is a tracking code called Criteo and they required to fill the following to make it work. Everything's fine except the viewBasket.