Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38738
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Find part match in array |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <9rCdnYySpppZSKTCnZ2dnUU7-N3NnZ2d@westnet.com.au> <1927146.oMNUckLgyt@PointedEars.de> <qumdnS2Bv-bgkabCnZ2dnUU7-fvNnZ2d@westnet.com.au> <XnsAC1D74C09A3AFeejj99@194.109.6.166> |
| Date | 2020-08-18 12:59 +0200 |
| Message-ID | <XnsAC1D843071097eejj99@194.109.6.166> (permalink) |
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote on 18 Aug 2020 in
comp.lang.javascript:
> Andrew Poulos <ap_prog@hotmail.com> wrote on 18 Aug 2020 in
> comp.lang.javascript:
>
>> Using String.prototype.includes is always case sensitive so if I need a
>> case insensitive test I'm going to need to convert the strings to, say,
>> lower case.
>>
>
> Object.defineProperty(
> String.prototype,
> 'contains',
> {
> value: function(p)
> { return this.toLowerCase().includes(p.toLowerCase()); }
> }
> );
>
> console.log( 'aaa'.contains( 'a' ) ); // true
> console.log( 'aaa'.contains( 'A' ) ); // true
> console.log( 'aaa'.contains( 'B' ) ); // false
Simpler:
String.prototype['contains'] = function(p)
{ return this.toLowerCase().includes(p.toLowerCase()); };
console.log( 'aaa'.contains( 'a' ) ); // true
console.log( 'aaa'.contains( 'A' ) ); // true
console.log( 'aaa'.contains( 'B' ) ); // false
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Find part match in array Andrew Poulos <ap_prog@hotmail.com> - 2020-08-17 10:56 +1000
Re: Find part match in array Andrew Poulos <ap_prog@hotmail.com> - 2020-08-17 13:06 +1000
Re: Find part match in array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-08-16 20:54 -0700
Re: Find part match in array JJ <jj4public@vfemail.net> - 2020-08-17 16:36 +0700
Re: Find part match in array Julio Di Egidio <julio@diegidio.name> - 2020-08-17 05:01 -0700
Re: Find part match in array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-17 19:36 +0200
Re: Find part match in array Andrew Poulos <ap_prog@hotmail.com> - 2020-08-18 09:02 +1000
Re: Find part match in array Andrew Poulos <ap_prog@hotmail.com> - 2020-08-18 13:09 +1000
Re: Find part match in array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-18 11:28 +0200
Re: Find part match in array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-08-18 12:59 +0200
Re: Find part match in array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-18 21:59 +0200
csiph-web