Many times we use checkbox in the form control and post the form using jquery ajax and then we are required to access those form data from client side scripts, like Javascript. Among all possible form control, dropdown box, checkbox and radio buttons are having multiple options to select. So, we need to push all selected values of these form controls into an array using Javascript
Tag » Array
Delete element by value from array (not by key)
While working with array in PHP sometimes we need to check if a value exists in an array and delete that key and value together from array. This simple code snippet below with explanation will help you to understand how can you delete element by value from array (not by key).
Only variables should be passed by reference
Sometime we face a unique type of problem during development and we watch the code thoroughly but not find the error where we are getting. ‘Only variables should be passed by reference‘ in $file_extension = end(explode(‘.’, $file_name)) is the same type of problem which does not seem as error in our code and it happens in usual code.
4 ways to empty an array in JavaScript
JavaScript arrays are commonly used by developers and making them empty is also used in practice. Here I am describing 4 ways to empty an array in JavaScript:
1. Use splice() method
2. Set length to zero
3. Using pop() method
4. Set array to new empty array
Array in JavaScript – push() Method
Array in JavaScript push() method appends the given element or elements in the last of array. It returns the length of the new array.
Syntax is as below:
array.push(item1, item2,.....itemN);
Array in JavaScript – slice() Method
Array in JavaScript has slice() method that is used to extract a section of an array. This method returns a new array.
Syntax is as below:
array.slice( begin [,end] );
Array in JavaScript – sort() Method
sort() method for Array in JavaScript is used to sort the elements in that array.
Array in JavaScript – splice() Method
Array in JavaScript has splice() method that changes the elements of an array, adding new elements as well as removing old.
splice() method for Array in JavaScript is powerful method that let you modify an existing array. You can add, remove elements or replace existing elements.
Array in JavaScript – unshift() Method
Array unshift() method adds one or more elements to the beginning of an existing array and returns the new length of the array in Javascript.
Array in javascript
Array is most important keyword used in programming languages. Like other languages, Array is also used in javascript. Array in JavaScript is used to store multiple values in a single variable. Arrays in javascript is as special type of object