Javascript Get Array First Element Example
Apr 08, 2021 . Admin

<!DOCTYPE html> <html> <head> <title>Javascript - How to check if array first element?-MyWebtuts.com</title> </head> <body> <script> var arr = [ 1, 2, 3, 4, 5 ]; var first = arr.slice(0,1).shift(); alert(first); </script> </body> </html>Output: 1
1Example: 2 In this example i will use attribute for onclick event.
<!DOCTYPE html> <html> <head> <title>Javascript - How to check if array first element?-MyWebtuts.com</title> </head> <body> <script> var arr = ['php', 'laravel', 'java', 'cs', 'cf' ]; const [first] = arr; console.log(first); </script> </body> </html>Output: 2
php
It will help you....