Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to create an array from a text field. I need to paste fifty lines into a text field. Then convert the lines to an array, with each line being a different element in the array.
Given an input field like this:
<textarea id="myInput"></textarea>
You can get the value from the text field as follows:
var myValue = document.getElementById("myInput").value;
And then split it like this
var myArray = myValue.split("\n");
Related
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 last year.
The community is reviewing whether to reopen this question as of 12 months ago.
Improve this question
I am trying to write a regex to extract the items in the text below that start with the # and ends with )
const bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)";
So basically, will want an array that looks like:
["#[DataStructures](topic_DataStructures)", "#[Algorithms](topic_Algorithms)", "#[Make or Mar](topic_Make or Mar)"]
Using string match() we can try:
var bodyOfText = "#[DataStructures](topic_DataStructures) is one #[Algorithms](topic_Algorithms) branch that could #[Make or Mar](topic_Make or Mar)";
var matches = bodyOfText.match(/#\[.*?\]\(.*?\)/g);
console.log(matches);
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 1 year ago.
Improve this question
With the following array of strings in javascript, is there a way to use the .filter to filter by the first word?
['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two']
For example to .filter(x = 'Desk_*')
['Desk_One', 'Desk_Two', 'Desk_Three']
Maybe this needs to be a regex
You can use startsWith() function like this:
let array = ['Desk_One', 'Desk_Two', 'Desk_Three', 'Chair_One', 'Chair_Two'];
let result = array.filter((item)=>item.startsWith(array[0].split('_')[0]));
console.log(result)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How to Display each variable of for loop in a div tag using javascript? Using innerHTML i am only able to display the last variable of for loop
You can do as follows, but it is better to use lists.
Lists: https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/ul
const myDreams = ["Fly", "Be rich", "Go to the moon"];
const myDreamsDiv = document.querySelector("#myDreams");
//The secret here is to add a breakline(<br>) between each word.
myDreams.forEach(dream => myDreamsDiv.innerHTML += (dream + "<br>"));
<div id="myDreams"></div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a string
var str="[a54hy 8:45pm],[f57gh 9:20]"
i need to get
[f57gh 9:20pm]
I don't want to use split since the string length can be anything
This worked for me. where id is f57gh
var re='\\['+id + '([a-z0-9: ]+)\\]';
var rematch=RegExp(re,'g');
var mydata=str.match(rematch);
alert(mydata); //[f57gh 9:11am]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been wondering if I can print a string with each letter having a different color.
If I can do this can anybody tell me how ?
You can't directly set the color (or any part of the style) of a letter, you have first to wrap it in its own element so that you can style it. Here's an example :
var e = document.getElementById('s');
e.innerHTML = e.innerHTML.split('').map(function(l){
return '<span style="color:#'
+Math.floor(Math.random()*16777216).toString(16)
+'">'+l+'<span>'
}).join('');
Demonstration