Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Join() in jQuery?

What is Join() in jquery? for example:

var newText = $("p").text().split(" ").join("</span> <span>");  
like image 851
mSafdel Avatar asked Oct 20 '09 10:10

mSafdel


People also ask

What is join () in JS?

join() The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.

What is array join ()?

JavaScript Array join() The join() method returns an array as a string. The join() method does not change the original array. Any separator can be specified. The default is comma (,).

How do you join strings?

The join() method takes all items in an iterable and joins them into one string. A string must be specified as the separator.

What is the use of join() function in jQuery?

It is a javascript replaceAll () on strings. var s = 'stackoverflow_is_cool'; s = s.split ('_').join (' '); console.log (s); join is not a jQuery function .Its a javascript function. The join () method joins the elements of an array into a string, and returns the string.The elements will be separated by a specified separator.

How to join elements of an array using jQuery?

join is not a jQuery function .Its a javascript function. The join () method joins the elements of an array into a string, and returns the string.The elements will be separated by a specified separator. The default separator is comma (,). newText = $ ("p").text ().split (" ").join (" or "); $ ('div').text (newText);

What does the Join () method do in Java?

The join () method returns an array as a string. The join () method does not change the original array. Any separator can be specified. The default is comma (,).

What is join in SQL Server?

SQL Joins. ❮ Previous Next ❯. A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Let's look at a selection from the "Orders" table: Then, look at a selection from the "Customers" table:


2 Answers

That's not a jQuery function - it's the regular Array.join function.

It converts an array to a string, putting the argument between each element.

like image 79
Greg Avatar answered Nov 09 '22 07:11

Greg


You would probably use your example like this

var newText = "<span>" + $("p").text().split(" ").join("</span> <span>") + "</span>"; 

This will put span tags around all the words in you paragraphs, turning

<p>Test is a demo.</p> 

into

<p><span>Test</span> <span>is</span> <span>a</span> <span>demo.</span></p> 

I do not know what the practical use of this could be.

like image 33
Jan Aagaard Avatar answered Nov 09 '22 06:11

Jan Aagaard