amp-index-of Array Utility

1.1.0 · abandoned · verified Wed Apr 22

The `amp-index-of` package provides a lightweight utility function for arrays, serving as an `indexOf` implementation similar to `Array.prototype.indexOf`. It is a component of the Ampersand.js ecosystem, a modular, non-frameworky framework for client-side JavaScript applications, initially popular in the mid-2010s. The package is at version 1.1.0 and has not seen active development or releases for several years, aligning with the broader inactivity of the Ampersand.js project. Its original purpose was to offer a consistent array utility within the Ampersand.js environment. However, in modern JavaScript development, direct use of native `Array.prototype.indexOf` is preferred due to universal browser support and native performance. Therefore, `amp-index-of` is considered abandoned and primarily serves historical contexts or legacy applications built with Ampersand.js. Its release cadence was tied to the now-inactive Ampersand.js development cycle.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `amp-index-of` function to find the index of an element in an array using CommonJS syntax.

const indexOf = require('amp-index-of');

const myArray = ['apple', 'banana', 'orange', 'grape', 'banana'];

// Find the first occurrence of 'banana'
const firstIndex = indexOf(myArray, 'banana');
console.log(`First 'banana' found at index: ${firstIndex}`); // Expected: 1

// Find an element that does not exist
const notFoundIndex = indexOf(myArray, 'kiwi');
console.log(`'kiwi' found at index: ${notFoundIndex}`); // Expected: -1

// Demonstrating behavior similar to Array.prototype.indexOf
const anotherArray = [10, 20, 30, 10, 40];
console.log(`Native indexOf of 10: ${anotherArray.indexOf(10)}`); // Expected: 0
console.log(`amp-index-of of 10: ${indexOf(anotherArray, 10)}`); // Expected: 0

view raw JSON →