Table of Contents
Introduction
हेलो दोस्तों आज हम इस post में javascript array methods के बारेमे जानेगे तो पहले ये समजते है! की ये array क्या होता है!.
तो array collection of any type data मतलब की array एक special variable होता है जो एक से ज्यादा value को store (collect)
करता है!. javascript में array को आसानी से create किया जाता है!.
syntax:
const array_name = ['item1','item2',....]
const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter'];
Javascript array methods जैसे की
- – pop()
- – push()
- – reverse()
- – shift()
- – unshift()
- – concat()
- – find()
- – incluedes()
- – indexOf()
- – join()
- – lastIndexOf()
- – slice()
- – some()
- – tostring()
- – copywith()
- – fill()
- – filter()
- – foreach()
- – splice()
javascript pop() method
javascript में pop() method array के last element को remove कर देता है और return में array से remove की हुवी value को return देता है!.
syntax:
array.pop()
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log(myarr.pop()); </script>
javascript push() method
Javascript में push() method array में new element value को add करता है और push() method new array की length return करता है!.
syntax:
array.push(item1, item2, ..., itemX)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log(myarr.push("magento")); </script>
javascrip reverse() method
javascript में reverse() method एक array element को उलट देती है यानि की array element के order को reverse कर देती है!.
syntax:
array.reverse()
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log(myarr.reverse()); </script>
javscript shift() method
javascript में shift() method array का first element को remove कर देती है और बाकि के element को lower index में shift करती है!. shift() method array से remove की value को return करता है!.
syntax:
array.shift()
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log(myarr.shift()); </script>
javascript unshift() method
javascript में unshift() method array के सरुअत में new element को add करती है। unshift() method new array की length return करती है!
syntax:
array.unshift(item1, item2, ..., itemX)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log(myarr.unshift('Bootstrap')); </script>
javascript concat() method
concat() method दो और उससे ज्यादा arrays को join (merge) करने के लिए है!. concat() method new array को return करता है!.
syntax:
array.concat(array1,array2.....arrayn);
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; const newarr = ['python','javascript','Reactjs']; //console.log( myarr.concat(newarr)); </script>
javascript find() method
javascript में arr.find() method का इस्तेमाल array से पहले element value को get करने के लिए किया जाता है!. जो provide की गई condition अगर satisfies होती है तो या functin array के सभी elements की जाँच करता है और जोबी पहले element condition को satisfies करता है उसको वह print कर देता है!.
syntax:
array.find(function(currentvalue,index,arr),thisvalue);
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; // console.log(myarr.find(function(element){ // return element == 'css'; // })); </script>
javascript includes() method
includes() method array में specified value को check करने के लिए कर सकते है!. अगर array में specified value होती है तो वह true return करेगा वरना वह false return देगा!.
syntax:
array.includes(element,start)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log( myarr.includes('php')); </script>
javascript indexOf() method
indexOf() method किसी specified value की first index return देती है!. अगर value नहीं मिलती है तो indexOf method -1 लोटती है!. indexOf method एक specified index से start होती है और left to right search करती है!.
syntax:
array.indexOf(value,start);
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log( myarr.indexOf('wordpress')); </script>
javascript lastIndexOf() method
lastIndexOf() method specified value को last index लोटती है!. lastIndexOf() method -1 लोटती है अगर value नहीं मिलती है!. lastIndexOf() method एक specified index से सरु होता है और right to left search करता है!.
syntax:
array.lastIndexOf(item,start)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log( myarr.lastIndexOf('laravel')); </script>
javascript join() method
join() method एक array को एक string के रूप में लोटती है!. join method original array को नहीं बदलती है!. join() method array to string में separator के साथ लोटती है!.
syntax:
array.join(separator);
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log( myarr.join(' , ')); </script>
javascript slice() method
slice() method एक array में selected element का एक नया array लोटती है!. slice() method में दिए गए start से end तक के element को select करती है!. slice() method original array को नहीं बदलती है!.
syntax:
array.slice(start, end)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; //console.log( myarr.slice(2,5) ); </script>
javascript some() method
some() method हर एक element के लिए एक बार callback function executes करती है!. यदि some() array element में से किसी एक के लिए true लोटती है अगर callback function में दी गई condition satisfied होती है तो. और some() method empty array के लिए execute नहीं करती है!. और some() method original array को नहीं change करती है!.
syntax:
array.some(function(value, index, arr), this)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log(myarr.some(function(element){ return element == 'css'; })); </script>
javascript toString() method
toString() method comma से separate किये गई array value के साथ एक string लोटती है!. toString() method original array को नहीं बदलती है!.
syntax:
array.toString()
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log( myarr.toString() ); </script>
javascript copyWithin() method
copyWithin() method array element को array में किसी दूसरी position पर copy करती है!. copyWithin() method array mojud value को overwrites कर देती है!. copyWithin() method array में items को add नहीं करती है!.
syntax:
array.copyWithin(target, start, end)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log( myarr.copyWithin(2,0) ); </script>
javascript fill() method
fill() method एक array में specified elements को एक value के साथ भारती है!. fill() method original array को overwrite कर देती है!. start और end की position specified करनी होती है!. यदि नहीं तो सभी element overwrite हो जायेंगे!.
syntax:
array.fill(value, start, end)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log( myarr.fill('dev',2,4) ); </script>
javascript filter() method
filter() method elements से भरे एक नया array create करता है!. जो किसी function के दयारा provide की test pass करती है। filter() method empty array के लिए execute नहीं करती है!. filter() method original array को नहीं दबलती है!.
syntax:
array.filter(function(currentValue, index, arr), thisValue)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log(myarr.filter(function(element){ return element == 'wordpress'; })); </script>
javascript forEach() method
forEach() method एक array में हर एक element के लिए function को call करती है!. empty array के लिए forEach() method execute नहीं करती है!.
syntax:
array.forEach(function(currentValue, index, arr), thisValue)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log(myarr.forEach(function(i,v){ console.log(i); })); </script>
javascript splice() method
splice() method array elements को जोड़ती है या removes करती है!. splice() method original array को overwrites कर deti है!.
syntax:
array.splice(index, howmany, item1, ....., itemX)
Example:
<script> const myarr = ['HTML','css','php','wordpress','shopify','laravel','codeigniter']; console.log( myarr.splice(2,4) ); </script>