CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other
Showing posts with label JavaScript Arrays. Show all posts
Showing posts with label JavaScript Arrays. Show all posts

04 January, 2019

Introduction to JavaScript Arrays

 Programing Coderfunda     January 04, 2019     JavaScript, JavaScript Arrays     No comments   

JavaScript Arrays in Hindi
Arrays एक ही तरह की values का collection होता है। एक तरह की value से मतलब है या तो केवल strings या केवल integers या फिर floating point numbers आदि। Arrays को बहुत सारे variables create करने के problem से बचने के लिए यूज़ किया जाता हैं।

जैसे की यदि आप 200 employees के नाम store करना चाहते है तो उसके लिए आपको 200 variables create करने की जरुरत नहीं है। आप एक array create कर सकते है जिसमे 200 नाम store किये जा सकते है। ऐसा करने से programmers का time बचता है। 

Array का हर element uniquely identify किया जा सकता है। Array values को indexing के द्वारा store करता है। लेकिन ये बात हमेशा याद रखे की array की index zero से शुरू होती है। इसलिए उपर बताये गए example में पहला नाम 0 index पर और आखिर नाम 199 index पर होगा। Array की किसी भी value को आप array के नाम और उसके index number के द्वारा access कर सकते है।

आपको ये बात भी हमेशा याद रखनी चाहिए की JavaScript में arrays object है। इसलिए आप इनको new keyword के द्वारा create करते है। हालाँकि JavaScript आपको directly values put करने का option भी provide करती है लेकिन तब भी JavaScript में arrays objects ही रहते है।

Creating JavaScript Arrays 

JavaScript में arrays 2 तरह से create किये जा सकते है। ये दोनों ही तरीके अलग अलग situation के according यूज़ किये जा सकते है।
  • Directly  - इस तरीके में आप array create करने के साथ ही value भी डालते है। ये array create करने का combined तरीका है।        
  • With new keyword - इस तरीके में आप array को object की तरह create करते है। इस तरीके में पहले array create किया जाता है और बाद में values डाली जा सकती है। आप चाहे तो साथ में ही values डाल सकते है इसके लिए आप array object का constructor यूज़ करते है।   
दोनों ही तरीके अलग अलग situations में need के according यूज़ किये जा सकते है। इनके बारे में नीचे  दिया जा रहा है।

Directly (Combined Way)

इस तरीके में array create करना बहुत ही simple है। इसका structure नीचे दिया जा रहा है। 
var array_Name = [value1,value2,.....valueN]; 
   
इस तरीके में var keyword के बाद array का नाम लिखा जाता है। Array का नाम unique होना चाहिए। Array के नाम के बाद assignment operator लगा कर angular brackets में array की values दी जाती है। Values को comma से separate किया जाता है।

इसका उदाहरण नीचे दिया जा रहा है।
<!-- javascriptArrayDemo.html -->

<html>
<head>
<title>Javascript array demo</title>
</head>
<body>

<script type="text/javascript">
// Array declaration 
var empName = ["Sam","Sally","Tina","Raghav","John"];
// Printing array elements
for(i=0;i<5;i++)
{
     document.write(empName[i],"\n");
}
</script>

</body>
</html> 

ऊपर दी गयी script निचे दिया गया web page generate करती है।

With New Keyword 

इस तरीके से array create करने के लिए आप new keyword यूज़ करते है। ये कोई object create करने जैसा ही है। इसका structure नीचे दिया जा रहा है। 
var array_Name = new Array();
array_Name[0] = value1;
array_Name[1] = value2;
...
...
array_Name[n] = valueN;
यदि आप values भी साथ में ही डालना चाहते है तो आप निचे दिए गए structure से array create कर सकते है।
var array_Name = new Array(value1, value2);

उपर वाले तरीके में पहले array create किया गया है उसके बाद index numbers के द्वारा values दी गई है। नीचे  वाले तरीके में Array object के constructor के द्वारा values put की गई है। ये values constructor automatically index numbers को assign कर देता है।

इसका उदाहरण नीचे दिया जा रहा है। 
<!-- arrayNewKeywordDemo.html -->

<html>
<head>
<title>Javascript new keyword demo</title>
</head>
<body>

<script type="text/javascript">
// Array declaration using new keyword
var empName = new Array("Angelina","Sam");
// Printing array elements
for(i=0;i<2;i++)
{
    document.write(empName[i]);
}
</script>

</body>
</html>      

ऊपर दी गयी script निचे दिया गया webpage generate करती है।

JavaScript Arrays Length Property

JavaScript आपको array object के साथ length property provide करती है। ये property आपके array की length hold करती है। इस property को access करने का structure नीचे दिया गया है। 
array_Name.length;
   
आप चाहे तो इस property को loop control करने के लिए यूज़ कर सकते है। इसका उदाहरण नीचे दिया जा रहा है। 
<script type="text/javascript">
var empAge = new Array(24,42,22,55,23,30);

// Displaying length of array 
document.write("Length of array is "+empAge.length);

// Iterating loop upto array length
for(var i=0;i<empAge.length;i++)
{
    document.write(empAge[i]);
}
</script> a


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Meta

Popular Posts

  • Crawl and Index Your Website with Laravel Site Search
      Laravel Site Search   is a package by Spatie to create a full-text search index by crawling your site. You can think of it as a private Go...
  • JqueryUI - Show
    JqueryUI - Show, JqueryUI,  This chapter will discuss the show() method, which is one of the methods used to manage jQueryUI visual effe...
  • WordPress Table
    WordPress Table WordPress table is an easy way to show the data in the table format. In the past, we had used the HTML code or table plugin ...
  • SpinLock VB.Net Example From MSDN Possibly Produces Incorrect Behaviour
    The code below is part of an example from MSDN. It is the example on how to use SpinLock but to my eye there is a race condition in it. Why ...
  • Introduction to JavaScript Strings
      JavaScript Strings JavaScript में strings objects होती है। एक string object में characters की sequence store की जाती है। जैसे की Best Hi...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (69)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • July (4)
  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda