Array की Length
Array length यह count करने जैसा है कि carton में असल में कितने eggs हैं। यह बताता है कि आपकी list में अभी कितने items हैं।
In this page:
Syntax
${#array_name[@]}
Array Length
${#array[@]} array में currently मौजूद elements की संख्या देता है। यह दोनों indexed और associative arrays के लिए काम करता है। यह आमतौर पर loop bound के रूप में उपयोग होता है जब numeric index से iterate करना हो बजाय foreach-style iteration के।
Note:
${#array[@]}elements count करता है${#array[0]}(बिना@) इसके बजाय सिर्फ पहले element के string की length देता है।
उदाहरण: Array Length
#!/bin/bash
items=("pen" "notebook" "eraser" "ruler")
echo "Number of items: ${#items[@]}"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
${#arr}उपयोग करना और पहले item की length मिलना, जब count${#arr[@]}है।- यह उम्मीद करना कि length highest index हो, जब यह items की संख्या है।
- यह भूल जाना कि unset indexes gaps छोड़ते हैं, इसलिए count last index plus one से छोटा होता है।
🔒
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: