I am trying to filter an array of full names by a specific first name. I have created the filterFirstName function which accepts arguments for the name and the criteria to compare it to. I then use that function in my filter. I looked up the syntax for filter callback(element[, index[, array]]. The element is the fullName but the nameQuery
Tag: string
How do you delete every line inside of a string that doesn’t contain a specific word?
There’s a string with multiple lines of random characters, I’d like to delete every line that doesn’t contain the word :tesTWORD: For example, this part of the original string Would turn into this: So basically all lines that don’t contain the exact word :tesTWORD: get deleted. I have tried a bunch of different things like playing around with arrays, but
How could I replace repeated complex strings in javascript? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago. Improve this question For example, the input would be: @[facts.::ip](facts.::ip) = “127.0.0.1” AND @[facts.::os](facts.::os) = “ubuntu” I would like to transform that into:
How to replace square brackets and set dot before replacement?
Good day. I wish to replace square brackets inside string and set dot before replacement. For example, Current string position[0].type i need transform to next one position.0.type I have tried making it by this rule ‘position[0].type’.replace(/[[]]/g, ”) as expected, will removed only brackets, how i can set needed dot? Thanks. Answer You can use The [[].]+ regex matches one or
How to encode string in javaScript
I am doing an exercise, the task is: I need to write a function which takes an argument a string and returns encoded string, for example: aaabbcccc -> should return 3a2b4c. I wrote the function, I created an object where I have all characters counted but I don’t know how to return value and key converted into the string. Here
Why does using a String.split(regex) include an empty string at the beginning of resulting array?
I have a string data that is a numbered list (e.g. “1.Line 1n2. Line 2nLine 2 Continuedn3. Line 3”) I tried making a regex that splits the string into [“Line 1n”, “Line 2nLine 2 Continuedn”, “Line 3”] and I made this regex const reg = /d+./gm. When I use the following regex via data.split(reg), I do see the elements in
JavaScript: Search string from position
JavaScript has two useful methods, both which nearly do what I need. String.prototype.indexOf() will search for a substring and return its position. It has an optional position parameter which is the starting point of the search, so you can easily find the next one. String.prototype.search() will search a string using a regular expression and return its position. However, as far
Advice on how to resolve an issue with extracting only numbers from a string using JavaScript
I’m new to stackoverflow and would appreciate some advice to help me solve this problem. I have two strings that I want to extract numbers from String 1 = “12.3,Name1,3,4,Name2,35,Name3” returns [12.3,3,4,35] Which is the required result. String 2 = “12.3,22,Q” returns [12.322] Which is the incorrect result, It should be [12.3,22] I have commented on my code with the
How to replace list of words with tag at multiple indexes in Javascript
I have a response of parent string which I have to modify and replace with the provided start and end indexes. Expected Final Result: I tried below approach but was not successful Usage: please ignore my example names couldn’t think anything more Answer EDIT: My previous answer did not account to duplicate and did not use your indexes, so here
Regex expression not returning entire term
The intention of the regex is to capture substrings wrapped between twin expressions in parentheses, kinda like html tags. For example: And here’s my code Can anyone tell me why this doesn’t capture the entire thing? Answer The characters () are special in a regexp and must be escaped with a if you want to match them literally. And