Bird
0
0

Given $arr1 = @(1, 2) and $arr2 = @(3, 4), which command combines them into a single array @(1, 2, 3, 4)?

hard📝 Application Q9 of 15
PowerShell - Variables and Data Types
Given $arr1 = @(1, 2) and $arr2 = @(3, 4), which command combines them into a single array @(1, 2, 3, 4)?
A$combined = Join-Array $arr1 $arr2
B$combined = $arr1 + $arr2
C$combined = $arr1 | $arr2
D$combined = $arr1, $arr2
Step-by-Step Solution
Solution:
  1. Step 1: Understand array concatenation in PowerShell

    The plus operator + concatenates two arrays into one.
  2. Step 2: Identify the correct syntax

    $combined = $arr1 + $arr2 uses $arr1 + $arr2 which combines both arrays into one.
  3. Final Answer:

    $combined = $arr1 + $arr2 -> Option B
  4. Quick Check:

    Concatenate arrays with + operator [OK]
Quick Trick: Use + to join arrays [OK]
Common Mistakes:
  • Using commas which create nested arrays
  • Using pipeline operator incorrectly
  • Using non-existent Join-Array command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes