Javascript Course


The array_map(), and array_search() functions are generally known and used in PHP. These functions are useful when working with arrays. JavaScript has similar functions, but with other syntax.

array.map()

The array.map(callback) method returns an array containing all the elements of array after applying the callback function to each one.
- Example:
var arr = [1, 4, 9, 16];

//creates an array with the values from arr, doubled
const arr2 = arr.map((v, i)=>v*2);

console.log(arr2); //[2, 8, 18, 32]

array.indexOf()

The JavaScript array.indexOf(value) method is equivalent to the php array_search(value, array) function, it searches the array for a given value and returns the corresponding index if successful, or -1 if none is found.
- Example:
let arr =['ab', 'cd', 90];
var ixv = arr.indexOf('cd');
if(ixv !=-1) document.write('<p>arr contains the value: cd, with index: '+ixv+'</p>');

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
array_map and array_search in JavaScript

Last accessed pages

  1. Integer and Float value in Select with PDO from string to numeric (8672)
  2. Get and change IFrame content through a JavaScript script created in another IFrame (16553)
  3. Shape Tween - Flash Animation (6185)
  4. CSS Border (6122)
  5. Disable button and Enable it after specified time (17587)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (524)
  2. CSS cursor property - Custom Cursors (70)
  3. The Mastery of Love (50)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (48)
  5. Read Excel file data in PHP - PhpExcelReader (46)