Skip to main content
Question Protected by Sebastian Simon
Formatting; more modern code.
Source Link
Sebastian Simon
  • 19k
  • 8
  • 60
  • 82

In javascript, how How do you search an array for a substring match?

I need to search an array in javascriptJavaScript. The search would be for only part of the string to match as the string would have addtional numbers assigned to itadditional components. I would then need to return the successfully matched array element with the full string.

i.e.Example:

var windowArray = new Array ("item","thing","id-3-text","class");
const windowArray = [ "item", "thing", "id-3-text", "class" ];

I need to search for the array element with "id-" in it and iI need to pull the rest of the text in the element as well (iei.e. "id-3-text").

ThanksHow do I do that?

In javascript, how do you search an array for a substring match

I need to search an array in javascript. The search would be for only part of the string to match as the string would have addtional numbers assigned to it. I would then need to return the successfully matched array element with the full string.

i.e.

var windowArray = new Array ("item","thing","id-3-text","class");

I need to search for the array element with "id-" in it and i need to pull the rest of the text in the element as well (ie. "id-3-text").

Thanks

How do you search an array for a substring match?

I need to search an array in JavaScript. The search would be for only part of the string to match as the string would have additional components. I would then need to return the successfully matched array element with the full string.

Example:

const windowArray = [ "item", "thing", "id-3-text", "class" ];

I need to search for the array element with "id-" in it and I need to pull the rest of the text in the element as well (i.e. "id-3-text").

How do I do that?

fixed formatting
Source Link
zzzzBov
  • 178k
  • 55
  • 324
  • 370

I need to search an array in javascript. The search would be for only part of the string to match as the string would have addtional numbers assigned to it. I would then need to return the successfully matched array element with the full string.

iei.e.

var windowArray = new Array ("item","thing","id-3-text","class");
var windowArray = new Array ("item","thing","id-3-text","class");

I need to search for the array element with "id-""id-" in it and i need to pull the rest of the text in the element as well (ie. "id-3-text""id-3-text").

Thanks

I need to search an array in javascript. The search would be for only part of the string to match as the string would have addtional numbers assigned to it. I would then need to return the successfully matched array element with the full string.

ie.

var windowArray = new Array ("item","thing","id-3-text","class");

I need to search for the array element with "id-" in it and i need to pull the rest of the text in the element as well (ie. "id-3-text").

Thanks

I need to search an array in javascript. The search would be for only part of the string to match as the string would have addtional numbers assigned to it. I would then need to return the successfully matched array element with the full string.

i.e.

var windowArray = new Array ("item","thing","id-3-text","class");

I need to search for the array element with "id-" in it and i need to pull the rest of the text in the element as well (ie. "id-3-text").

Thanks

added differentiator to title
Link
T.J. Crowder
  • 1.1m
  • 196
  • 2k
  • 1.9k

In javascript, how do you search an array for a substring match

Source Link
reub77
  • 1.2k
  • 2
  • 10
  • 12
Loading