--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - indexOf([4, 5, 6], 5) - indexOf('banana', 'n') returns: - '1' - '2' dependencies: - python/_helpers/_operator authors: original by: - Kevin van Zonneveld (https://kvz.io) notes: - >- Finds the first matching element or substring like Python's operator.indexOf. parityVerified: - Python 3.12 isTypescript: true type: function layout: function title: Python's operator.indexOf in TypeScript description: >- Here's what our current TypeScript equivalent to Python's operator.indexOf looks like. function: indexOf category: operator language: python permalink: python/operator/indexOf/ alias: - /functions/python/indexOf/ - /functions/operator/indexOf/ - /python/indexOf/ ---
{% codeblock lang:typescript %}import { pythonIndexOf } from '../_helpers/_operator.ts' export function indexOf(a: unknown, b: unknown): number { // discuss at: https://locutus.io/python/operator/indexOf/ // parity verified: Python 3.12 // original by: Kevin van Zonneveld (https://kvz.io) // note 1: Finds the first matching element or substring like Python's operator.indexOf. // example 1: indexOf([4, 5, 6], 5) // returns 1: 1 // example 2: indexOf('banana', 'n') // returns 2: 2 return pythonIndexOf(a, b) } {% endcodeblock %}