28 lines
		
	
	
		
			654 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
		
		
			
		
	
	
			28 lines
		
	
	
		
			654 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| 
								 | 
							
								---
							 | 
						||
| 
								 | 
							
								title: Array Length
							 | 
						||
| 
								 | 
							
								---
							 | 
						||
| 
								 | 
							
								## Array Length
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								`length` is a property of arrays in JavaScript that returns or sets the number of elements in a given array.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								The `length` property of an array can be returned like so.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								```js
							 | 
						||
| 
								 | 
							
								let desserts = ["Cake", "Pie", "Brownies"];
							 | 
						||
| 
								 | 
							
								console.log(desserts.length); // 3
							 | 
						||
| 
								 | 
							
								```
							 | 
						||
| 
								 | 
							
								The assignment operator, in conjunction with the `length` property, can be used to set then number of elements in an array like so.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								```js
							 | 
						||
| 
								 | 
							
								let cars = ["Saab", "BMW", "Volvo"];
							 | 
						||
| 
								 | 
							
								cars.length = 2;
							 | 
						||
| 
								 | 
							
								console.log(cars.length); // 2
							 | 
						||
| 
								 | 
							
								```
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#### More Information:
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 |