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 HTML element can be used to embed a SWF flash content?
<object> <div> <script>
<object type="application/x-shockwave-flash" data="file.swf" width="500" height="250">
 <param name="src" value="file.swf" />
 Your browser not support SWF.
</object>
Which CSS pseudo-class adds a style to an input form field that has keyboard input focus?
:active :focus :hover
input:focus {
  background-color: #88fe88;
}
Click on the instruction which converts a JSON string into a JavaScript object.
JSON.stringify(javascript_object) object.toString() JSON.parse(json_string)
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses"}';
var obj = JSON.parse(jsnstr);
alert(obj.url);
Indicate the PHP function which can be used to create or write a file on server.
fopen() file_put_contents() file_get_contents()
if (file_put_contents("file.txt", "content")) echo "The file was created";
else echo "The file can not be created";
array_map and array_search in JavaScript

Last accessed pages

  1. Using v-model in form input fields (1051)
  2. jQuery UI draggable - Drag elements (11445)
  3. Display data from PHP Array, or MySQL in HTML table (26980)
  4. Redirects (4978)
  5. jsSHA - SHA Hashes and HMAC in JavaScript (3519)

Popular pages this month

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