Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 49
» Latest member: antwantillman
» Forum threads: 4,492
» Forum posts: 4,495

Full Statistics

Online Users
There are currently 1035 online users.
» 0 Member(s) | 1033 Guest(s)
Bing, Yandex

Latest Threads
SELECT statement with MS ...
Forum: MS Access SQL Tutorials
Last Post: Qomplainerz
07-27-2023, 03:35 PM
» Replies: 0
» Views: 1,080
SELECT statement with the...
Forum: MS Access SQL Tutorials
Last Post: Qomplainerz
07-27-2023, 03:31 PM
» Replies: 0
» Views: 529
Creating hyperlinks in HT...
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 01:23 PM
» Replies: 0
» Views: 829
What's new in HTML5?
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 12:48 PM
» Replies: 0
» Views: 555
What is HTML5?
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 12:43 PM
» Replies: 0
» Views: 520
Neck isometric exercises
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:44 AM
» Replies: 0
» Views: 811
Shoulder shrug
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:43 AM
» Replies: 0
» Views: 476
Neck retraction
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:43 AM
» Replies: 0
» Views: 438
Neck flexion and extensio...
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:42 AM
» Replies: 0
» Views: 506
Neck rotation
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:42 AM
» Replies: 0
» Views: 478

 
  JavaScript Array findIndex() examples (returns the index)
Posted by: Qomplainerz - 04-04-2023, 08:10 AM - Forum: JavaScript Tutorials - No Replies

The HTML part between the <body></body> tags looks like this:

Code:
<h2>Example 1</h2>
<p id="demo"></p>
<h2>Example 2</h2>
<p>Click "Test" to return the index of the first array element that has a value above this number:</p>
<p><input type="number" id="toCheck" value="18"></p>
<button onclick="myFunction()">Test</button>
<p id="demo2"></p>


The JavaScript part looks like this:

Code:
// Example 1

const ages = [3, 10, 18, 20];

function checkAge(age)
{
  return age > 18;
}

document.getElementById("demo").innerHTML = ages.findIndex(checkAge);

// Example 2

const numbers = [4, 12, 16, 20];

function checkValue(x)
{
  return x > document.getElementById("toCheck").value;
}

function myFunction()
{
  document.getElementById("demo2").innerHTML = numbers.findIndex(checkValue);
}

Print this item

  JavaScript - Additions with values
Posted by: Qomplainerz - 04-04-2023, 08:05 AM - Forum: JavaScript Tutorials - No Replies

Code:
let x = 100 + 50;

document.getElementById("demo").innerHTML = x;

Print this item

  JavaScript - Additions with variables
Posted by: Qomplainerz - 04-04-2023, 08:05 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 100;
let b = 50;
let x = a + b;

document.getElementById("demo").innerHTML = x;

Print this item

  JavaScript - Additions with expressions
Posted by: Qomplainerz - 04-04-2023, 08:04 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 3;
let x = (100 + 50) + a;

document.getElementById("demo").innerHTML = x;

Print this item

  JavaScript - Subtractions with values
Posted by: Qomplainerz - 04-04-2023, 08:04 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 10 - 5;

document.getElementById("demo").innerHTML = a;

Print this item

  JavaScript - Subtractions with variables
Posted by: Qomplainerz - 04-04-2023, 08:03 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 10;
let b = 5;
let c = a - b;

document.getElementById("demo").innerHTML = c;

Print this item

  JavaScript - Subtractions with expressions
Posted by: Qomplainerz - 04-04-2023, 08:02 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 1;
let b = (10 - 1) - a;

document.getElementById("demo").innerHTML = b;

Print this item

  JavaScript - Multiplications with values
Posted by: Qomplainerz - 04-04-2023, 08:02 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 2 * 2;

document.getElementById("demo").innerHTML = a;

Print this item

  JavaScript - Multiplications with variables
Posted by: Qomplainerz - 04-04-2023, 08:01 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 2;
let b = 2;
let c = a * b;

document.getElementById("demo").innerHTML = c;

Print this item

  JavaScript - Multiplications with expressions
Posted by: Qomplainerz - 04-04-2023, 08:01 AM - Forum: JavaScript Tutorials - No Replies

Code:
let a = 2;
let b = (2 * 2) * 2;

document.getElementById("demo").innerHTML = b;

Print this item