Lädt...


🔧 Searching for a Value in an Array Using JavaScript.


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

This program demonstrates how to search for a specific val within an array using a while loop in JavaScript. The user is prompted to enter a value, and the program then checks if this value exists in a predefined variety. If the value is found, a message indicating its availability is displayed; otherwise, a message indicating its absence is shown.

Simple Example:

let Val = prompt("Enter Value ..!");
let numbers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300];

let i = 0;
let Find = false;
while (i < numbers.length) {
  if (numbers[i] == Val) {
    Find = true;
    break;
  }
  i++;
}
if (Find) {
  console.log("Available Variable..!");
} else {
  console.log("No Available Variable..!");
}

Output:

100 This Variable Available in the Array..!

Finding an Element in an Array Using DOM in JavaScript:
In this program, we demonstrate how to search for a specific value within an array using a while loop in JavaScript. The user enters a value in an input field, and the program checks if this value exists in a predefined array. If the value is found, a message indicating its availability is displayed; otherwise, a message indicating its absence is shown.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Find Element in Array Using DOM in JavaScript </title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        h4, h2 {
            color: #333;
        }
        input {
            padding: 10px;
            margin-right: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        button {
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            background-color: #28a745;
            color: white;
            cursor: pointer;
        }
        button:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>
    <h4>Find Element in Array</h4>
    <h4 id="NumData"></h4>
    <input type="text" placeholder="Enter Value" id="Num" />
    <button onclick="SearchEle()">Find</button>
    <h2 id="Ans"></h2>

    <script>
        let Data = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300];
        document.getElementById("NumData").innerHTML += "Our Array is: " + Data.join(', ');

        function SearchEle() {
            let NewValue = document.getElementById("Num").value;
            let i = 0;
            let Find = false;
            while (i < Data.length) {
                if (Data[i] == NewValue) {
                    Find = true;
                    break;
                }
                i++;
            }

            if (Find) {
                document.getElementById("Ans").innerHTML = `${NewValue} 
                is Available..!`;
            } else {
                document.getElementById("Ans").innerHTML = `${NewValue} 
               is not Available..!`;
            }
        }
    </script>
</body>
</html>

Output:

Image description

Image description

...

🔧 Searching for a Value in an Array Using JavaScript.


📈 42.73 Punkte
🔧 Programmierung

🔧 Upcoming JavaScript Features: Simplifying Array Combinations with `Array.zip` and `Array.zipKeyed`


📈 35.8 Punkte
🔧 Programmierung

🔧 Array Searching in DSA using JavaScript: From Basics to Advanced


📈 33.8 Punkte
🔧 Programmierung

🔧 Searching an Element in an Array with JavaScript


📈 29.86 Punkte
🔧 Programmierung

🔧 Find Array Element in the Array using JavaScript


📈 29.63 Punkte
🔧 Programmierung

🔧 Find Array Element in the Array using JavaScript


📈 29.63 Punkte
🔧 Programmierung

🔧 How to extract value of a property as array from an array of objects ?


📈 29.17 Punkte
🔧 Programmierung

🐧 How to Change Value of Object Which is Inside an Array Using JavaScript?


📈 28.43 Punkte
🐧 Linux Tipps

🔧 Find the maximum value of the K-th smallest usage value in Array


📈 27.98 Punkte
🔧 Programmierung

🔧 JS Sum of an Array – How to Add the Numbers in a JavaScript Array


📈 25.68 Punkte
🔧 Programmierung

🔧 JavaScript Array Tutorial – Array Methods in JS


📈 25.68 Punkte
🔧 Programmierung

🔧 JavaScript Sort Array - How to Sort an Array Accurately


📈 25.68 Punkte
🔧 Programmierung

🐧 Convert Array of Starings to Array of Numbers in JavaScript


📈 25.68 Punkte
🐧 Linux Tipps

🔧 Learn the JavaScript Array.every() and Array.some() methods


📈 25.68 Punkte
🔧 Programmierung

🔧 JavaScript: Arrays, Array Properties, Array Methods: push, pop, shift, unshift, Stacks, and Queues!


📈 25.68 Punkte
🔧 Programmierung

🔧 Select Element in Array() to a new Array() JavaScript


📈 25.68 Punkte
🔧 Programmierung

🔧 JavaScript Array Length – How to Find the Length of an Array in JS


📈 25.68 Punkte
🔧 Programmierung

🐧 Getting a Random Value From a JavaScript Array


📈 24.49 Punkte
🐧 Linux Tipps

🐧 How to Check if an Array Includes a Value in JavaScript


📈 24.49 Punkte
🐧 Linux Tipps

🔧 2 Crystal Ball Searching Problem Solved Using Javascript


📈 23.68 Punkte
🔧 Programmierung

🔧 Searching Algorithm Using Javascript


📈 23.68 Punkte
🔧 Programmierung

🔧 Exploring the Core of true value vs false value in JavaScript...


📈 23.3 Punkte
🔧 Programmierung

🐧 Get Minimum and Maximum Value of an Arduino Array Using min() and max() Function


📈 23 Punkte
🐧 Linux Tipps

🔧 Minimum value that can’t be formed using OR of elements of the Array


📈 23 Punkte
🔧 Programmierung

🐧 How to Define a Default Value for “input type=text” Without Using Attribute ‘value’?


📈 21.81 Punkte
🐧 Linux Tipps

🕵️ FFmpeg Array Access MXF File Out-of-Array Pufferüberlauf


📈 20.24 Punkte
🕵️ Sicherheitslücken

🔧 When to use if-else, switch-case, or functions like Array.prototype.includes() or Array.prototype.find()


📈 20.24 Punkte
🔧 Programmierung

💾 Microsoft Edge Chakra JIT Array.prototype.reverse Array Type Confusion


📈 20.24 Punkte
💾 IT Security Tools

🔧 2022. Convert 1D Array Into 2D Array


📈 20.24 Punkte
🔧 Programmierung

⚠️ Microsoft Edge Chakra JIT Array.prototype.reverse Array Type Confusion


📈 20.24 Punkte
⚠️ PoC

🔧 Array.slice vs. Array.splice: Clearing Up the Confusion


📈 20.24 Punkte
🔧 Programmierung

⚠️ #0daytoday #Microsoft Edge Chakra JIT - Array.prototype.reverse Array Type Confusion Exploit [#0day #Exploit]


📈 20.24 Punkte
⚠️ PoC

🔧 Bubble Sort: Given an Array of Unsorted Items, Return A Sorted Array


📈 20.24 Punkte
🔧 Programmierung

⚠️ [dos] Microsoft Edge Chakra JIT - 'Array.prototype.reverse' Array Type Confusion


📈 20.24 Punkte
⚠️ PoC

matomo