JavaScript Tutorial For Beginners #25 - Slice and Split Strings
HTML-код
- Опубликовано: 10 сен 2024
- Yo ninjas, I just want to show you a couple of neat little string methods (functions) in this JavaScript tutorial. The slice method and the split method. The slice method literally 'slices' your string into a new segment defined by starting and ending points. The split method, splits a string into multiple 'pockets' and puts them into an array (great for splitting tags).
As always, any questions, fire away below :).
SUBSCRIBE TO CHANNEL - / @netninja
========== JavaScript for Beginners Playlist ==========
• JavaScript Tutorials f...
========== CSS for Beginners Playlist ==========
• CSS Tutorials For Begi...
========== HTML for Beginners Playlist ==========
• HTML Tutorials For Beg...
========== The Net Ninja ============
For more front-end development tutorials & to black-belt your coding skills, head over to - / @netninja or thenetninja.co.uk
========== Social Links ==========
Twitter - @TheNetNinja - / thenetninjauk
I love how short and simple these vids are. Thanks
I actually was planning to use split, so searched that in RUclips. But while watching this video, I realised slice is more fitting for my purpose. Cheers!
This tutorial made me hungry for prok~!
But, f'reals though, you and the tutorials you make are awesome!
A very nice balance of thorough, to-the-point lecturing, and light-hearted feels.
Please keep doing what you do!
var spy = "I was loving you"
var spy2 = spy.slice(0);
var spy3 = spy2.slice(6);
document.write(spy3 + " daily NetNinja");
var spy = "I was loving you";
console.log(spy.slice(6) + " daily NetNinja");
// much easier :D
This channel is so great, you explain so simple and nietly!
the best explanation of arrays
I like how you just jump into the subject matter.
sure feeling like having a little prok right now!
Haha
Im eating a cake while watching this video and I can really taste the layer! Okay i'll stop...
Thank you man for the help
It really helped. Thanks
Help a lot man. Thx
when we put slice(2,9) then why 2nd digit is included and 9th one is not to be. In str2.
is the mozilla page link in description missing.
Here is the link-
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
Awesome, thanks for sharing.
You save me
Cannot read property 'slice' of null
this is printing on my developers tool
this video was uploaded on my birthdate. nice
You are 5 years old?
@@kevinmackey3166 wish i could be, but i am 23
thank you bro
so helpfull
var t="rup,vars,abhi,sai,ana" this is the statment i wrote
i got 'rup,vars,abhi,sai,ana'(getting in single quotes ' ')
hope i will get the answer.
Can some one guide me how can i slice a specific string of array which includes number in it
how would you do this with shapes
Hi, and what is when i want to slice the string from backwards?
str.slice(-6); // Finds the last 6 characters.
OR
str.slice(-6, -2); // Finds the last 6 characters except the last 2.
How can we strip out the leading spaces from array positions >0?
+Benny Powers Hey, on a string, to strip out the spaces, you can use the replace method. On arrays, you could use a for loop to cycle through and remove any empty elements.
use comma and space in quotations
.split(", ")
instead of just comma in quotations
.split(",")
HEY NET NINJA, how do i split let alphabet = "abcdefghijklmnopqrstuvwxyz" into a single character with space [let alphabet1= alphabet.split(" ") ; ] is not working
Hello
Nelson Ongiti
,
you can do it something like that:
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var alphabetSplit = alphabet.match(/.{1}/g);
console.log(alphabetSplit);
@@ukaszcezary8870 Better simple solution
const alphabet = "abcdefghijklmnopqrstuvwxyz";
const alphabetSplit = alphabet.split("");
console.log(alphabetSplit);
const alphabet = "abcdefghijklmnopqrstuvwxyz";
const alphabetSpacedSplit = alphabet.split("").map(value => value + " ").join("").trim();
console.log(alphabetSpacedSplit);
Hello,
how can I split a string without using the split function? What is the basic function for it?
16 dislikers are the ones who split strings to "llo, wo"
what about negative slice numbers?
+annie khaliq Hey :). Using negative numbers, we'd just start at the end position of the array/string and count from there.
If var stuff = "pencil?", then stuff.slice(-5) = "ncil?". Basically, it will return all characters leading up to that number, but in reverse. stuff.slice(5) = "penci".
It's similar to the .length property.
Stuff.length - 1 gives you the last character of the string, just like stuff(-1) will also return the last letter.