Updated April 11, 2023
Below is the syntax:
Array_with_set_of_elements.from(object_reference, map_function, thisValue)
Significance of the above-mentioned arguments or the parameter passed with Array_with_set_of_elements.from function is as follows:
- Object_reference: This argument is used to convert the referenced object into an array.
- map_function: It is a kind of optional parameter that is used when a map function is used to call any specific item from the defined array.
- thisValue: It is also a kind of optional parameter that is used when a map function is executed with this as value to be used.
The return value, in this case, is that it returns a new Array instance of elements that are almost the same as the considered set of arrays.
Here, B refer to the element or the alphabet as a part of string.
The array from() method is part of Array references which is considered as an extension for creating a new set of array instance from a given array. In case it is a need to create an array with a set of elements as an alphabet within a string then a new array with set of alphabets to be referred into a new array is used to get an entire new array.
As mentioned, Object can be accessed using object property similarly to String() method inside array list of object properties is used to access the alphabet relevant to the element of the string.
This example is used to define the string of array and retrieval of elements from that array with the help of getElementById() method used to get the sequence or the list of elements as described in the output.
<!DOCTYPE html> <html> <body> <h1>To Display Array.from() method </h1> <p>Creating an Array from a String:</p> <p id="demo"></p> <p><strong>Note:</strong> This Array.from() method is not supported in IDE 11 (and earlier versions).</p> <script> var myArr = Array.from("M,N,O,P,Q,R,S,T"); document.getElementById("demo").innerHTML = myArr; </script> </body> </html>
This example represents an array of 32- bit unsigned integer of string like structure and then returns a new array unsigned integer array as described in the output.
<!DOCTYPE html> <html> <body> <h1>To Display Array.from() method using unsigned integer 35 </h1> <p>Creating an Array from a String:</p> <p id="demo"></p> <script> var array = Uint32Array.from('981896509983573456'); document.write(array); </script> </body> </html>
This example represents an array of 32-bit unsigned integer of string array by dividing with 32 to each number with using the function.
<!DOCTYPE html> <html> <body> <h1>To Display Array.from() method using unsigned integer 35 in an grouped manner </h1> <p>Creating an Array from a String:</p> <p id="demo3"></p> <script> var array = Uint32Array.from([256897, 125648, 326589, 258748, 23432, 52345, 4345, 2432 ], z => z / 32); document.write(array); </script> </body> </html>
This example is used to represent the string in the considered array getting converted into a set of new converted array.
This example is used to illustrate the array from () method to represent with the set of length of elements which in this case is the set of names passed as an argument.
Array from() method is a very useful method compared to other methods of Java References as it helps in accessing the elements using length and object reference property within the array elements.