slice() Function in Javascript
slice() function இங்கு நாம் கொடுக்கும் index position களை பொருத்து குறிப்பிட்ட string ஐ slice செய்து எடுப்பதற்கு பயன்படுகிறது.
string.slice(start,end)
Example1
<script>
var input = "You carry the passport to your own happiness";
var res = input.slice(0,22);
document.writeln(res);
</script>
மேலே உள்ள Example1-ஐ கவனிக்கவும் இங்கு input என்ற variable இல் "You carry the passport to your own happiness" என்ற string value ஆனது store செய்யபட்டுள்ளது.இங்கு input.slice(0,22) என்ற function பயன்படுத்தபடுகிறது, இங்கு start index position 0 மற்றும் end index position 22 என கொடுகப்பட்டுள்ளது. எனவே நமக்கு output You carry the passport என கிடைக்கிறது.
You carry the passport
Example2
<script>
var data = "I choose to make the rest of my life the best of my life";
var res = data.slice(0,36);
document.writeln(res);
</script>
மேலே உள்ள Example2-ஐ கவனிக்கவும் இங்கு data என்ற variable இல் "I choose to make the rest of my life the best of my life" என்ற string value ஆனது store செய்யபட்டுள்ளது. இங்கு data.slice(0,36) என்ற function பயன்படுத்தபடுகிறது, இங்கு start index position 0 மற்றும் end index position 36 என கொடுகப்பட்டுள்ளது. எனவே நமக்கு output I choose to make the rest of my life என கிடைக்கிறது.output ஐ கவனிக்கவும்.
I choose to make the rest of my life
இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.
Comments