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 :hoverinput: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";